Django: Temporarily redirect all URLs to one view

Viewed 2657

I am building site and thought it would be nice to have some sort of maintenance page where I could redirect users if need be.

How can I start redirecting all requests to one specific view? I am using Constance to have maintenance switch in my admin view (just a bool value). Its value is then available thorough the project.

I've already prepared another list of urlpatterns but cannot figure out how to dynamically change them so the redirect works.

maintenance_urlpatterns = [
    url(r'^$', views.maintenance, name='maintenance'),
]

This is urls.py file from app, not the project one which I would leave alone.

I also thought about modifying base.html template and rendering "maintenance page" this way, but I think that is pretty bad solution.

EDIT: To clarify. My main question isnt how to write urlpattern that will capture all traffic, but how to edit these dynamically in response to Constance config change. So I can toggle that in admin.

1 Answers
Related