英文:
urlpattern Regex is not working as expected
问题
urlpatterns = [ path(r'/.*', maintenance_view, name='maintenance') ]
英文:
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')
]
答案1
得分: 0
我自己找到了答案。问题是我必须使用re_path
,而且在正则表达式中,Django 不关心“/”,所以我将其移除。
from django.urls import re_path
urlpatterns=[
re_path(r'.*', maintenance_view, name='maintenance')
]
英文:
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')
]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论