[Answered ]-Django URL with catch all except /admin and /blog

2👍

You don’t need to handle this manually with a RedirectView. You likely need to add the CommonMiddleware to your MIDDLEWARE_CLASSES settings if it is not already in there.
(inserting ‘django.middleware.common.CommonMiddleware’ into that list or tuple). It usually goes near the top of that declaration. Its documentation is here:

https://docs.djangoproject.com/en/1.5/ref/middleware/#django.middleware.common.CommonMiddleware

You also need to be sure APPEND_SLASH is set to True in your settings.

Furthermore, your last pattern is likely to match anything, which I suspect could be the real culprit of your problem. A URL without a trailing slash has to fail to match any patterns in order for it to automatically redirect to one with a trailing slash per that middleware. I think you can fix the last URL pattern by appending /$ to that pattern

👤csmith

0👍

The admin and blog urls have trailing slashes i.e. /admin/ and /blog/. The urls with the trailing slashes should work at the moment.

If you want to make the urls work without the slash, you could add entries for /admin and /blog, and use RedirectView to redirect.

Leave a comment