Django-allauth:我如何为我的域名添加一个站点?

11

我是 Django 的新手,已经安装了 django-allauth。

我按照文档进行操作,但在后续的安装步骤上卡住了:

  1. 为你的域名添加一个与 settings.SITE_ID (django.contrib.sites 应用程序) 匹配的网站。

  2. 对于每个基于 OAuth 的提供者,添加一个社交应用程序 (socialaccount 应用程序)。

  3. 填写从提供者获取的网站和 OAuth 应用凭据。

这一部分我完全不理解。

我尝试注册网站和社交账号,但没有任何变化。另外,我发现需要定义 Site ID,所以我将它放在我的设置中:

SITE_ID = '1'

请问,有人能帮我解决这个问题吗?任何帮助都将不胜感激。

更新

我找到了一篇教程,让我继续进行。我在Facebook上注册了一个应用程序,并获得了APP ID和secret,我在/admin/socialaccount/socialapp/上进行了设置,但即使一切准备就绪,我仍然遇到了问题:

      Page not found (404)
Request Method: GET
Request URL:    MyIP/accounts/profile/
Using the URLconf defined in gameproject.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/
^accounts/ ^weibo/
^accounts/ ^persona/login/$ [name='persona_login']
^accounts/ ^instagram/
^accounts/ ^openid/login/$ [name='openid_login']
^accounts/ ^openid/callback/$ [name='openid_callback']
^accounts/ ^vimeo/
^accounts/ ^twitter/
^accounts/ ^vk/
^accounts/ ^linkedin/
^accounts/ ^github/
^accounts/ ^google/
^accounts/ ^facebook/
^accounts/ ^facebook/login/token/$ [name='facebook_login_by_token']
^accounts/ ^facebook/channel/$ [name='facebook_channel']
^accounts/ ^angellist/
^accounts/ ^bitly/
^accounts/ ^dropbox/
^accounts/ ^stackexchange/
^accounts/ ^twitch/
^accounts/ ^soundcloud/
The current URL, accounts/profile/, didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.

当我尝试检查我的网站在MYIP/accounts/profile/时。

我们愿意帮助,但是有一种提问方式可以引出好的答案。你有两个问题。第一个问题是“如何将一个网站添加到我的项目中?”第二个问题是“如何让allauth与Facebook合作?”这是两个完全不同的问题,应该分别作为两个不同的SO问题提出。如果第一个问题已经解决了,那么你应该删除这个问题,并提出一个新的问题。如果没有解决,那么请编辑你的问题,将重点放在网站问题上,并为Facebook问题开一个新的问题。或者如果你认为这两个问题之间存在实质性的关联,请澄清一下。 - Louis
3
我查看 https://speakerdeck.com/tedtieken/signing-up-and-signing-in-users-in-django-with-django-allauth 来回答我的问题。 - user3387367
3个回答

11
  1. 通过管理面板添加网站。由于我在本地开发,所以将“Domain Name”字段设置为“127.0.0.1:8000”,而“Display Name”则无所谓。

  2. 您的settings.py文件中的SITE_ID需要匹配通过管理面板添加的实际数据库ID。为此,您可以转到通过管理面板创建的Site的详细信息,并查看ID号码的url。我的结果是“5”(我重新创建了几个站点来尝试使其工作)。

  3. 通过管理面板创建社交应用程序。这很容易,因为您只需通过提供商设置一个应用程序(例如,在Facebook网站上创建Facebook应用程序),并使用他们给您的秘密代码和应用程序ID填写django表单。务必将步骤1中创建的django Site添加到您正在进行此步骤的Social Application中。

注意:我这样做时一直收到404错误。这是由于我已登录为管理员,因此url“/accounts/login”认为我已经登录,并重定向到尚不存在的“/accounts/profile”。如果您遇到此问题,可以轻松解决,只需清除您django页面的cookie并再次访问“/accounts/login”即可。如果需要帮助,请在评论中留言。


1
你的“注意事项”帮了我大忙 :) - binithb

0

检查在Django设置的INSTALLED_APPS部分中是否已添加django.contrib.site


-2

安装后

在Django根目录下执行以下命令以创建数据库表:

python manage.py syncdb

现在启动您的服务器,访问您的管理页面(例如http://localhost:8000/admin/),并按照以下步骤操作:

  1. 为您的域名添加一个与settings.SITE_IDdjango.contrib.sites应用程序)匹配的站点。
  2. 对于每个基于OAuth的提供者,请添加一个Social App(socialaccount应用程序)。
  3. 填写从provider获取的站点和OAuth应用程序credentials

enter image description here


1
这个回答没有帮助。我会在弄清楚后再发帖;我也很难理解安装后需要做什么。 - Dylan

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