问题
I need to implement two separate login/logout URLs for my Django app, for two different types of users. My client wants to differentiate the URLs for customers and for employees, even though it's using the same user database. Mostly for branding purposes.
For employees:
/login /logout
For customers:
/survey/login /survey/logout
What's the best way of doing this without reinventing the whole login/logout process?
回答1:
If there's truly no difference, just attach the auth views to the different URLs (You can have multiple URLs go to the same view).
urlpatterns = (
(r'^login/$', 'django.contrib.auth.views.login'),
(r'^logout/$', 'django.contrib.auth.views.logout'),
(r'^survey/login/$', 'django.contrib.auth.views.login', {'template_name': 'survey_login.html'}),
(r'^survey/logout/$', 'django.contrib.auth.views.logout', {'template_name': 'survey_logout.html'}), #Please notice the typo
)
回答2:
You can point both sets of patterns to the same view functions. To handle redirects for the type of user, etc, you could look at the path or a value on your user's account to differentiate.
来源:https://stackoverflow.com/questions/9385861/multiple-login-urls-for-single-django-application