[1.11] Django loads sub-string url

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[1.11] Django loads sub-string url

Henrik Baran
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

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/e5d1b683-c6e3-8bc8-01f3-853ff4cb97ca%40posteo.de.
For more options, visit https://groups.google.com/d/optout.

signature.asc (484 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [1.11] Django loads sub-string url

Daniel Roseman-2
On Sunday, 18 February 2018 16:19:31 UTC, Henrik Baran wrote:
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


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.

--
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 [hidden email].
To post to this group, send email to [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|

Re: [1.11] Django loads sub-string url

Henrik Baran
Hi Daniel,

thanks a lot, that solved it for me!


On 18.02.2018 19:25, Daniel Roseman wrote:
On Sunday, 18 February 2018 16:19:31 UTC, Henrik Baran wrote:
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


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.
--
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 [hidden email].
To post to this group, send email to [hidden email].
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.

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/857697f5-30b6-4cde-7422-63dd02fb2cae%40posteo.de.
For more options, visit https://groups.google.com/d/optout.

signature.asc (484 bytes) Download Attachment