Django-allauth基础设置

15

我试着按照最新的 http://django-allauth.readthedocs.org/en/latest/#installation 进行操作。

urls.py 文件应该长成这样:

urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    url(r'^accounts/', include('allauth.urls')),
)

settings.py文件包含:

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
)

TEMPLATE_CONTEXT_PROCESSORS = (
    # Required by allauth template tags
    "django.core.context_processors.request",
    "django.contrib.auth.context_processors.auth",
    # allauth specific context processors
    "allauth.account.context_processors.account",
    "allauth.socialaccount.context_processors.socialaccount",
)

AUTHENTICATION_BACKENDS = (
    # Needed to login by username in Django admin, regardless of `allauth`
    "django.contrib.auth.backends.ModelBackend",
    # `allauth` specific authentication methods, such as login by e-mail
    "allauth.account.auth_backends.AuthenticationBackend",
)
SITE_ID = 1

我运行了python manage.py syncdb命令,但当我访问我的本地地址 localhost:8000/accounts/login/ 时,它显示“Page Not Found (404)”页面。我还通过http://www.sarahhagstrom.com/2013/09/the-missing-django-allauth-tutorial/教程再次检查了我的操作,但我不确定还需要做些什么才能显示基本的登录界面。有任何建议吗?

编辑

除了“Page Not Found 404”错误外,这里还有其他错误信息。

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

当前的URL地址为accounts/profile/,与任何一个匹配项都不符。

1个回答

21

你好,只是确认一下:你是否已经启动了你的服务器?

python manage.py runserver

编辑:

看起来您正在尝试访问未注册的URL accounts/profile/。如果您转到 localhost:8000/accounts/register,它是否仍然出现错误?

另外,根据文档

当我尝试登录时,无法访问/accounts/profile/页面,出现 404 错误

当您到达此页面时,即表示您已成功登录。但是,您需要自己实现此 URL 的视图,因为要在此处显示的内容是项目特定的。您也可以决定将其重定向到其他位置。

看起来您需要为 accounts/profile/ 编写自己的视图。

如果您想的话,可以在 settings.py 中将登录重定向到其他页面。例如:

LOGIN_REDIRECT_URL = "/"

这将把你送回到你的主页。


哈哈,是的,我已经开始了。我可以在/admin部分看到为站点和社交账户创建的表格。 - newbieProgrammer
你能否提供更多关于你收到的错误的具体信息吗? - Alex
我刚刚更新了帖子,其中的错误似乎表明它包含了来自allauth.urls的URL。 - newbieProgrammer
1
好的,看看我的新编辑。我猜你已经登录了,所以它会将你重定向到你的LOGIN_REDIRECT_URL(在Django中默认为accounts/profile)。你需要做的是:要么(1)在你的设置中更改它,要么(2)添加一个URL和视图来处理accounts/profile/。如果有不明白的地方,请告诉我。 - Alex
没问题。继续努力。这只是需要多加练习。 - Alex
1
我真的很高兴看到这个。我刚开始使用AllAuth。为此,我必须登录管理员并设置应用程序配置文件。然后我做的第一件事就是尝试使用accounts/login进行测试,结果重定向到了不存在的profile页面。被引导到一个我没有指定且不存在的页面让我感到迷惑,而且很难判断是因为AllAuth看到我已经登录了。在看到这条评论后,我只需进入管理员并注销,BAM!一切正常。相当不错。 - Doug Bradshaw

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接