Reputation: 4838
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
from django.contrib import admin
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'),
)
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 ?
Upvotes: 3
Views: 3838
Reputation: 1738
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')
Upvotes: 7