have a url that accepts all characters

后端 未结 3 2071
离开以前
离开以前 2020-12-18 19:57

I want a url that accepts all characters,for example:

(r\'^company/(?P[a-zA-Z]+)/doclist/$\',\'CompanyHub.views.docList\')

for <

3条回答
  •  时光取名叫无心
    2020-12-18 20:54

    As others have said:

    (.*)
    

    ...will match all characters, but it will also match an empty string (which might be bad if the regex is at the end of a URL). If you want to force that at least one character is required, then use this:

    (.+)
    

    Just to be clear, these work in the middle of URLs as well as at the end, so something like this works perfectly fine:

    url(ur'^package\/(?P.+)\/(?P.+)', ... )
    

    (and as @tsikov says, use a preceding 'u' for unicode)

提交回复
热议问题