【问题标题】:django-allauth basic setupdjango-allauth 基本设置
【发布时间】:2014-05-21 15:40:56
【问题描述】:

我尝试关注最新的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/ 时,它给了我找不到页面 (404)。我还仔细检查了我在http://www.sarahhagstrom.com/2013/09/the-missing-django-allauth-tutorial/ 上的教程做了什么,但我不确定要显示基本登录屏幕还需要做什么。有什么指点吗?

编辑

除了找不到页面 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/,与其中任何一个都不匹配。

【问题讨论】:

    标签: django django-allauth


    【解决方案1】:

    只是为了检查:您是否启动了您的服务器?

    python manage.py runserver
    

    编辑:

    您似乎正在尝试accounts/profile/,这不是注册网址。去localhost:8000/accounts/register还是报错吗?

    另外,来自docs

    当我尝试登录时,我在 /accounts/profile/ 上遇到 404

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

    看来您需要为帐户/个人资料/编写自己的视图

    如果需要,您可以将登录重定向设置到 settings.py 中的不同页面。即:

    LOGIN_REDIRECT_URL = "/"
    

    这会将您带回您的主页。

    【讨论】:

    • 哈哈是的,我已经开始了。我可以在 /admin 部分看到为站点和社交帐户创建了表
    • 你能发布更多关于你收到的错误的细节吗?
    • 我刚刚用错误更新了帖子,似乎说它包含来自 allauth.urls 的网址
    • 好的,看看我的新编辑。我猜你已经登录了,所以它会将你重定向到你的 LOGIN_REDIRECT_URL (在 django 中默认是帐户/配置文件。你需要(1)在你的设置中更改它,或者(2)添加一个 url 和查看帐户/个人资料/。让我知道这是否有意义。
    • 我很高兴看到这个。我刚开始使用 AllAuth。为此,我必须登录管理员并设置应用程序配置文件。然后我做的第一件事是尝试使用帐户/登录对其进行测试,并将其重定向到不存在的配置文件。被定向到一个我没有指定但不存在的页面令人迷惑,很难说这是因为 AllAuth 看到我已经登录了。看到这个评论后,我只是去了管理员和注销和 BAM!一切正常。很整洁。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-06
    • 2019-06-26
    • 2012-02-27
    • 2016-04-06
    • 2014-08-20
    • 1970-01-01
    • 2013-05-24
    相关资源
    最近更新 更多