0

If I add to my urls.py

urlpatterns += [url(r'^(\S+)$', views.myview, name='myview') ]

I expect it to match "mysite.com/anything/" but it does not. Navigating to that URL in my browser adds "Not Found: /anything/" to my "error.log". It only appears to match URLs that do NOT end with "/". Why?

I tried explicitly adding the slash at the end

urlpatterns += [url(r'^(\S+)/$', views.myview, name='myview') ]

but still no match to "mysite.com/anything/"

The only way I can get a match is to avoid using the \S+. This matches:

urlpatterns += [url(r'^anything/$', views.myview, name='myview') ]

but defeats the purpose of the \S+ and what I want to do.

Mat
  • 275
  • 3
  • 12
  • '''APPEND_SLASH = True''' in settings.py might help or please try https://stackoverflow.com/questions/10408826/remove-leading-and-trailing-slash-in-python – Ruperto Feb 27 '21 at 02:12
  • My issue is that I can't match URLs ending with "/". APPEND_SLASH was true. Interestingly, if I set it to False Django won't match any URL, with or without a "/" at the end. – Mat Feb 28 '21 at 14:45
  • please try: ```urlpatterns += [url(r'^.+/$', views.myview, name='myview') ]``` – Ruperto Mar 01 '21 at 00:38

0 Answers0