Django catch-all URL without breaking APPEND_SLASH

后端 未结 2 840
醉话见心
醉话见心 2020-12-29 03:20

I have an entry in my urls.py that acts as a catch-all which loads a simple view if it finds an appropriate page in the database. The problem with this approach is that the

2条回答
  •  情话喂你
    2020-12-29 04:06

    Make sure that your catch-all URL pattern has a slash at the end, and that the pattern is the last in your URLconf. If the catch-all pattern doesn't end with a slash, then it will match stray URLs before the middleware tries appending a slash.

    For example, use r'^.*/$' instead of r'^.*' as your last pattern.

    To do the same, but pass the url to the view as a named argument, use r'^(?P.*)/$'.

提交回复
热议问题