What does this Django regular expression mean? `?P`

前端 未结 5 557
长情又很酷
长情又很酷 2021-01-30 00:46

I have the following regular expression (regex) in my urls.py and I\'d like to know what it means. Specifically the (?P portion o

5条回答
  •  离开以前
    2021-01-30 01:21

    (?P) creates a match group named category_slug.

    The regex itself matches a string starting with category/ and then a mix of alphanumeric characters, the dash - and the underscore _, followed by a trailing slash.

    Example URLs accepted by the regex:

    • category/foo/
    • category/foo_bar-baz/
    • category/12345/
    • category/q1e2_asdf/

提交回复
热议问题