首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么<myproject>/accounts/profile/显示<myproject>/profile/ page

为什么<myproject>/accounts/profile/显示<myproject>/profile/ page
EN

Stack Overflow用户
提问于 2019-08-25 03:31:47
回答 2查看 1.8K关注 0票数 2

使用django-allauth,在成功登录后,用户将被重定向到http://<myproject>/accounts/profile/.然而,这个URL不存在,但是它仍然成功地显示了来自http://<myproject>/profile/的视图

settings.py

代码语言:javascript
复制
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

代码语言:javascript
复制
urlpatterns = [
    path('', views.profile, name='profile'),
]

使用show_urls,我看不到/accounts/*的任何东西,它将调用view.profile视图

代码语言:javascript
复制
/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

只有实际/侧写/ url..。

代码语言:javascript
复制
/profile/       user_profile.views.profile      profile

帮助我理解为什么/accounts/profile/要显示/profile/视图..。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-08-25 06:01:38

您的profile url路径并不局限于只匹配url的开始:

代码语言:javascript
复制
    url('profile/', include('user_profile.urls')),

例如,这将匹配任何类似gibberishprofile/的内容,包括accounts/profile/。如果您将url配置更改为

代码语言:javascript
复制
    url('^profile/', include('user_profile.urls')),  # note the ^ before profile

那么只有profile/才能匹配。

票数 1
EN

Stack Overflow用户

发布于 2019-08-25 04:15:41

实际上,重定向到/accounts/profile/是django中的默认行为。在django全局设置中,它被定义为LOGIN_REDIRECT_URL。Django希望您实现这个页面/url。Django django-allauth还使用相同的设置在登录后重定向用户。

如果要重定向到任何其他页面(如/profile/ ),请在项目设置中重写此设置。

代码语言:javascript
复制
LOGIN_REDIRECT_URL = '/profile/'

或者,如果您希望django-allauth完全不重定向,请按照所描述的LOGIN_REDIRECT_URL = False设置在您的设置中设置这里

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57643029

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档