Reputation: 363
My django url works only when I use a slash after my url. Of the following two, only the second works. The first one does not work:
1). http://10.165.19.167:8000/downloady9cHTML/Intro.html/
2). http://10.165.19.167:8000/downloady9cHTML/Intro.html
What can I do if I want my second url to work? i.e. I dont want to put a back slash at the end of my url?
Thanks..
Upvotes: 0
Views: 881
Reputation: 599600
If you don't want to require a slash, don't put one in the URL pattern.
url(r'^downloady9cHTML/(?P<file_name>.*)$', ...)
Upvotes: 2
Reputation: 905
You need Django's APPEND_SLASH
When set to True, if the request URL does not match any of the patterns in the URLconf and it doesn’t end in a slash, an HTTP redirect is issued to the same URL with a slash appended. Note that the redirect may cause any data submitted in a POST request to be lost.
edit
url(r'^downloady9cHTML/(?P<file_name>.*)/$', app.views.download_y9cfile1)
to
url(r'^downloady9cHTML/(?P<file_name>.*)', app.views.download_y9cfile1)
The /$
at the end is removed. The reason being regex $
states end of the regex pattern. That means you are explicitly telling it to match with \
. If you remove only the \
then it will work for the second url (in your question)only. If you remove \$
it will work for both the urls.
Upvotes: 1