Django 为什么/accounts/profile/显示/profile/页面

Django 为什么/accounts/profile/显示/profile/页面,django,django-urls,django-allauth,Django,Django Urls,Django Allauth,使用django allauth,成功登录后,用户将重定向到http:///accounts/profile/... 然而,这个URL不存在,但它仍然成功地显示了来自的视图http:///profile/ 设置.py 用户\u配置文件\url.py 使用show_url,我看不到/accounts/*的任何内容,这将调用view.profile视图 帮助我理解为什么/accounts/profile/显示/profile/view…实际上重定向到/accounts/profile/是django

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

设置.py

用户\u配置文件\url.py

使用show_url,我看不到/accounts/*的任何内容,这将调用view.profile视图

帮助我理解为什么/accounts/profile/显示/profile/view…

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

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

LOGIN_REDIRECT_URL = '/profile/'
或者,如果您希望django allauth完全不重定向,请在所述设置中设置LOGIN\u redirect\u URL=False。

您的配置文件URL路径不限于仅匹配URL的开头:

    url('profile/', include('user_profile.urls')),
这将匹配任何类似gibberishprofile/的内容,例如,包括accounts/profile/。如果将url配置更改为

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

然后只有profile/匹配。

正确。我明白。但是我不知道在我的URL.py中我在哪里实现了这个视图。。这就是为什么我对为什么要渲染该视图感到困惑的原因。它是否重定向到/profile/或渲染与/profile/on/accounts/profile/?相同的页面?显示的url是/accounts/profile。所以它不是重定向,而是渲染
/profile/       user_profile.views.profile      profile
LOGIN_REDIRECT_URL = '/profile/'
    url('profile/', include('user_profile.urls')),
    url('^profile/', include('user_profile.urls')),  # note the ^ before profile