[1.11] Django loads sub-string url

10 views
Skip to first unread message

Henrik Baran

unread,
Feb 18, 2018, 11:19:31 AM2/18/18
to Django users
Hi,

I face a very weird phenomenon. I have following two urls established:

url(r'types/$', views.types, name='types'),
url(r'box_types/$', views.box_types, name='box types')


If I load "/types/" the view "types" is shown, all ok. In case I load "/box_types" unexpectedly also "types" is shown. However, I expect "box_types" to load. How is this possible? I tested with some other urls and it seem like in case a url string is a sub-string of another url, it always loads the sub-string url.

Is this a feature I am not aware of or are we looking on a bug?

Thanks for reply and best regards,
Henrik
signature.asc

Daniel Roseman

unread,
Feb 18, 2018, 1:25:32 PM2/18/18
to Django users
There is a bug, but it is in your regexes. You need to anchor the pattern to the start of the string: 

url(r'^types/$', views.types, name='types'),
url(r'^box_types/$', views.box_types, name='box types')

--
DR.

Henrik Baran

unread,
Feb 18, 2018, 4:49:19 PM2/18/18
to django...@googlegroups.com
Hi Daniel,

thanks a lot, that solved it for me!
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e31b2082-9b80-49a2-a8d4-c3007b155f48%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

signature.asc
Reply all
Reply to author
Forward
0 new messages