[Django]-Django urlpatterns frustrating problem with trailing slashes

10πŸ‘

βœ…

I just tried a similar sample and it worked as you wrote it. No need for /?, .* would match that anyway. What is the exact error you are getting? Maybe you have your view without the request parameter? I.e. views.cheeseapp_views should be something like:

def cheeseapp_views(request, reqPath):
    ...

Edit:

The pattern that you suggested catches the trailing slash into reqPath because * operator is greedy (take a look at docs.python.org/library/re.html). Try this instead:

(r'^(?P<reqPath>.*?)/?$', views.cheeseapp_views) 

note it’s .*? instead of .* to make it non-greedy.

πŸ‘€icyrock.com

Leave a comment