Say you have a full url of localhost:thisdir/callview/
I have noticed that in a urls.py file, an included namespace is written as:
(r'^thisdir/', include('thisdir.urls', namespace='thisdir)),
where a beginning string is checked, but not end, and a view call is done as:
(r'^callview/$', 'thisdir.views.index', name='myview')
with the $ to check end of string. If the include pattern breaks "thisdir/" off the full url to check for that section first, and I thought it checks each string section at a time (so "thisdir/" is at the end of string) why do I never see (r'^thisdir/$', ...)
thank you
https://docs.djangoproject.com/en/1.8/topics/http/urls/
Note that the regular expressions in this example don’t have a $ (end-of-string match character) but do include a trailing slash. Whenever Django encounters include() (django.conf.urls.include()), it chops off whatever part of the URL matched up to that point and sends the remaining string to the included URLconf for further processing.
If you terminated an include with a $
, then the rule would no longer match anything in the included file, because it would only match URLs ending in exactly the include regex.
The reason you never see it is because it would prevent the purpose of a URL include.
(r'^thisdir/$', <include>)
This would only match urls equal to thisdir/
due to the terminating $
. Therefore a url such as thisdir/foobar/
will not match and never be processed by an include.
On the other hand, if you leave the $
out of the regex, /thisdir/<anything>
will match the regex and therefore can be processed further by the included urls.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With