使用django-allauth,成功登录后,用户将重定向到http://<myproject>/accounts/profile/
...但是该URL不存在,但仍然可以成功显示来自http://<myproject>/profile/
的视图
settings.py
urlpatterns = [
path('', include('pages.urls')),
path('admin/', admin.site.urls),
url(r'^accounts/', include('allauth.urls')),
url('album/', include('albums.urls')),
url('profile/', include('user_profile.urls')),
]
user_profile \ urls.py
urlpatterns = [
path('', views.profile, name='profile'),
]
使用show_urls
我看不到/accounts/*
的任何东西,它们会调用view.profile
视图
/accounts/confirm-email/ allauth.account.views.EmailVerificationSentView account_email_verification_sent
/accounts/confirm-email/<key>/ allauth.account.views.ConfirmEmailView account_confirm_email
/accounts/email/ allauth.account.views.EmailView account_email
/accounts/inactive/ allauth.account.views.AccountInactiveView account_inactive
/accounts/login/ allauth.account.views.LoginView account_login
/accounts/logout/ allauth.account.views.LogoutView account_logout
/accounts/password/change/ allauth.account.views.PasswordChangeView account_change_password
/accounts/password/reset/ allauth.account.views.PasswordResetView account_reset_password
/accounts/password/reset/done/ allauth.account.views.PasswordResetDoneView account_reset_password_done
/accounts/password/reset/key/<uidb36>-<key>/ allauth.account.views.PasswordResetFromKeyView account_reset_password_from_key
/accounts/password/reset/key/done/ allauth.account.views.PasswordResetFromKeyDoneView account_reset_password_from_key_done
/accounts/password/set/ allauth.account.views.PasswordSetView account_set_password
/accounts/signup/ allauth.account.views.SignupView account_signup
/accounts/social/connections/ allauth.socialaccount.views.ConnectionsView socialaccount_connections
/accounts/social/login/cancelled/ allauth.socialaccount.views.LoginCancelledView socialaccount_login_cancelled
/accounts/social/login/error/ allauth.socialaccount.views.LoginErrorView socialaccount_login_error
/accounts/social/signup/ allauth.socialaccount.views.SignupView socialaccount_signup
仅实际的/ profile /网址...
/profile/ user_profile.views.profile profile
帮助我了解为什么/accounts/profile/
显示/profile/
视图...
答案 0 :(得分:1)
您的profile
网址路径不限于仅匹配网址的开头:
url('profile/', include('user_profile.urls')),
这将匹配诸如gibberishprofile/
之类的任何内容,包括accounts/profile/
。如果您将url配置更改为
url('^profile/', include('user_profile.urls')), # note the ^ before profile
然后只有profile/
将匹配。
答案 1 :(得分:0)
实际上,重定向到/accounts/profile/
是django中的默认行为。在django全局设置中,它定义为LOGIN_REDIRECT_URL
。 Django希望您实现此页面/ URL。 Django django-allauth
在登录后也使用相同的设置来重定向用户。
如果您想重定向到其他任何页面,例如/profile/
,请在项目设置中覆盖此设置。
LOGIN_REDIRECT_URL = '/profile/'
或者,如果您希望django-allauth
完全不按照here的说明重定向设置中的所有LOGIN_REDIRECT_URL = False
。