Django Allauth and urls



我有一个测试Django的开发环境。我在"本地"pyenv安装中运行Python 3.5.2。我有Django 1.10.2。我昨天发现了allauth注册插件,并一直在玩它,但遇到了一个障碍。

我的网站是"dev.my.domain.com"。目的是不会有任何"公共"信息在这个网站的生产版本。生产版本将被命名为"members.my.domain.com"。所以,我想知道"allauth"插件是否有可能让所有非/admin入站请求检查验证?

所以,请求:

  • dev.my.domain.com
  • dev.my.domain.com/foo
  • dev.my.domain.com/foo/../bar/..。

都应该检查是否正确。如果没有,那么我认为"allauth"将重定向到登录/注册页面。

我已经尝试将Members/urls.py文件设置为:

from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
    url(r'^$', include('allauth.urls')),
    url(r'^admin/', admin.site.urls),
]

,但炸弹与Page Not Found错误和DEBUG消息:

    Using the URLconf defined in Members.urls, Django tried these URL patterns, in this order:
    ^$ ^ ^signup/$ [name='account_signup']
    ^$ ^ ^login/$ [name='account_login']
    ^$ ^ ^logout/$ [name='account_logout']
    ^$ ^ ^password/change/$ [name='account_change_password']
    ^$ ^ ^password/set/$ [name='account_set_password']
    ^$ ^ ^inactive/$ [name='account_inactive']
    ^$ ^ ^email/$ [name='account_email']
    ^$ ^ ^confirm-email/$ [name='account_email_verification_sent']
    ^$ ^ ^confirm-email/(?P<key>[-:w]+)/$ [name='account_confirm_email']
    ^$ ^ ^password/reset/$ [name='account_reset_password']
    ^$ ^ ^password/reset/done/$ [name='account_reset_password_done']
    ^$ ^ ^password/reset/key/(?P<uidb36>[0-9A-Za-z]+)-(?P<key>.+)/$ [name='account_reset_password_from_key']
    ^$ ^ ^password/reset/key/done/$ [name='account_reset_password_from_key_done']
    ^$ ^social/
    ^$ ^google/
    ^$ ^facebook/
    ^$ ^facebook/login/token/$ [name='facebook_login_by_token']
    ^admin/
    The current URL, , didn't match any of these.

我向自己的无知低头,回到allauth文档,使用他们默认的urls设置:

from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
    url(r'^accounts/', include('allauth.urls')),
    url(r'^admin/', admin.site.urls),
]

,但它也会爆炸,显示未找到的页面和不同的消息:

    Using the URLconf defined in Members.urls, Django tried these URL patterns, in this order:
    ^accounts/
    ^admin/
    The current URL, , didn't match any of these.

我认为其余的"allauth"安装是正确的,但我错过了一些东西。

想法?

view.py文件中,您只需要做一点"过滤器"在给出页面之前,查看用户是否通过了身份验证。

一个例子是:

def myview(request):
    if request.user.is_authenticated:
         # do something if the user is authenticated, like showing a page.
    else:
        # do somthing else

重新分级url结构-只要尝试添加/accounts/到url, 404页面将显示你所有的结束点,如果你是在调试模式(Debug = True)。您还可以在文档中找到端点的所有url。

希望我正确理解了你的问题

最新更新