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.
The regex in your question will only match on /
(the root of your site). If you want to catch everything, just use ^
only. Every URL has a beginning, so ^
always matches.
url(r'^', views.maintenance, name='maintenance')
Of course, this depends upon your normal urlpatterns being disabled in some fashion. It sounds like maybe you have that covered already.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With