urlpattern Regex is not working as expected

Question:

I have a Django website and for the times that pages are not ready I want to redirect any URL to a specific maintenance page.

So in the urlpatterns of my website I added this regex expecting it to capture anything after / but it’s not working.
urlpatterns = [ path(r'/.*',maintenance_view,name='maintenance') ]

Asked By: Sepas

||

Answers:

I found the answer myself. The problem was that I had to use re_path and also in the regex django was not caring about the "/", so I removed it.

from django.urls import re_path    
urlpatterns=[
re_path(r'.*',maintenance_view, name='maintenance')
]
Answered By: Sepas
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.