django捕获任何URL? [英] django catching any url?
问题描述
当用户要求输入不需要的URL时,我试图找到一种显示django登录页面的方法吗?我应该使用哪种语法?截止到今天,我有
I am trying to find a way to display my django login page when the user ask for an unwanted url? Which syntax should I user ? As of today I have
from django.conf.urls import patterns, include, url
从django.contrib导入管理员
from django.contrib import admin
urlpatterns = pattern('',#示例:
urlpatterns = patterns('', # Examples:
url(r'^login' , 'database.views.index', name='login'),
url(r'^create-user/' , 'database.views.account_creation', name='create_user'),
url(r'^get-details/' , 'database.views.get_details', name='get-details'),
url(r'^upload-csv' , 'database.views.upload_csv', name='upload_csv'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
#url(r'^' , 'database.views.index', name='login'),
)
我希望如果用户要求一个疯狂的URL,它将被定向到登录URL(即view.index函数).有什么主意吗?
I would like that if a user ask for a crazy url, it would be directed to the login url (ie view.index function). Any idea ?
推荐答案
在不评论您是否应该执行此操作的情况下,Django会尝试按顺序匹配您的url模式.因此,如果您想要一个全面/全面的处理程序,请放在最后:
Without commenting on whether you should do this, Django will attempt to match your url patterns in order. So if you want a fall-through / catch-all handler, put this last:
url(r'^.*', 'database.views.index', name='unmatched')
这篇关于django捕获任何URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!