Stop writing any string based / for urls in Django (regex)

So, I am using Django to create a web service, but I have a regex problem in Urls.

I want to go to localhost / user / USERNAME / products / where username can be any character, not just \ w. I tried to grab it using this:

('^user/(?P<username>.+)/$', 'user'),
('^user/(?P<username>.+)/products/$', 'get_products'),

      

but it will write down the username USERNAME / products and send it to the user. How can I tell all possible characters EXCEPT the leading slash for any length except zero?

+3


source to share


1 answer


Use [^/]+

instead .+

.



Chris Pratt, .+?

, " " , . , .

+8









All Articles