Multiple Login URLs for Single Django Application

泄露秘密 提交于 2020-01-05 11:04:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!