代码之家  ›  专栏  ›  技术社区  ›  dangel

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

  •  0
  • dangel  · 技术社区  · 5 年前

    http://<myproject>/accounts/profile/ ... 但是这个URL不存在,但是它仍然成功地显示了视图 http://<myproject>/profile/

    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')),
    ]
    

    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/url。。。

    /profile/       user_profile.views.profile      profile
    

    帮我弄明白为什么 /accounts/profile/ 正在显示 /profile/ 查看。。。

    1 回复  |  直到 5 年前
        1
  •  1
  •   azundo    5 年前

    你的 profile

        url('profile/', include('user_profile.urls')),
    

    这个可以匹配任何类似的 gibberishprofile/ accounts/profile/ . 如果将url配置更改为

        url('^profile/', include('user_profile.urls')),  # note the ^ before profile
    

    只有这样 profile/ 会匹配的。

        2
  •  0
  •   Nafees Anwar    5 年前

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

    /profile/

    LOGIN_REDIRECT_URL = '/profile/'
    

    或者如果你想的话 LOGIN_REDIRECT_URL = False 在你所描述的设置中 here