Python Django:Twitter登录被重定向到示例域
我使用Python Django:Twitter登录被重定向到示例域,python,django,python-2.7,twitter,Python,Django,Python 2.7,Twitter,我使用django socialregistration允许用户在我的应用程序上使用他们的Twitter帐户登录 设置.py INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.cont
django socialregistration
允许用户在我的应用程序上使用他们的Twitter帐户登录
设置.py
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rango',
'django.contrib.sites',
'socialregistration',
'socialregistration.contrib.twitter'
)
...
...
TEMPLATE_CONTEXT_PROCESSORS = ('django.contrib.auth.context_processors.auth', 'django.core.context_processors.debug', 'django.core.context_processors.i18n', 'django.core.context_processors.media', 'django.core.context_processors.static', 'django.contrib.messages.context_processors.messages', 'django.core.context_processors.request',)
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'socialregistration.contrib.twitter.auth.TwitterAuth',
)
TWITTER_CONSUMER_KEY = 'XXXXXXXXXXXXXXXXXX'
TWITTER_CONSUMER_SECRET_KEY = 'XXXXXXXXXXXXXXXXXXXX'
SITE_ID = 1
SESSION_SERIALIZER='django.contrib.sessions.serializers.PickleSerializer'
url.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'GetEvangelized.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^rango/', include('rango.urls')),
url(r'^social/', include('socialregistration.urls',
namespace = 'socialregistration')))
模板
<body>
<h1>MicroCelebrity Form</h1><br>
{% load twitter %}
{% twitter_button %}
<br>
<form id="evangelized_form" method="post" action="/rango/fillform/">
{% csrf_token %}
{% for hidden in form.hidden_fields %}
{{ hidden }}
{% endfor %}
{% for field in form.visible_fields %}
{{ field.errors }}
<b>{{ field.help_text }}</b><br>
{{ field }}<br><br>
{% endfor %}
<input type="submit" name="submit" value="Submit" />
</form>
</body>
我的Twitter应用程序的设置如下:
http://example.com/social/twitter/callback/?oauth_token=_WtPXwAAAAAAgTIEAAABTim7zYE&oauth_verifier=TheZd4yPsHNCYEi6mPwIvkugirkz20yH
Callback URL http://127.0.0.1:8000/auth/twitter/callback
Sign in with Twitter Yes
App-only authentication https://api.twitter.com/oauth2/token
Request token URL https://api.twitter.com/oauth/request_token
Authorize URL https://api.twitter.com/oauth/authorize
Access token URL https://api.twitter.com/oauth/access_token
Website http://www.cloudclovis.com
Callback url http://127.0.0.1:8000/auth/twitter/callback
“示例域”网页意味着什么?当我点击该页面上的“更多信息”链接时,我被重定向到http://www.iana.org/domains/reserved
这是什么意思?我如何允许我的用户在我的应用程序中使用他们的Twitter帐户登录?文档中就有这样的说明: 也不是说Twitter不会接受 作为回调URL的有效域,因此 开发网站时必须使用 编辑:好的,我现在看到你已经做到了。
您可以提供有关错误的更多详细信息吗?由于默认站点为
example.com
,因此它将重定向到那里
如果处于开发模式,则需要将其更改为127.0.0.1:8000
要更改它,您可以使用默认的管理界面,或者只需使用django shell:
from django.contrib.sites.models import Site
site = Site.objects.get(pk=1)
site.domain = '127.0.0.1:8000'
site.save()
谢谢这对我有用。但是,现在如果用户从他/她的Twitter帐户登录,应用程序将被重定向到一个显示“会话已过期”的页面。如何从登录用户的Twitter凭据中提取其电子邮件ID和名称?我知道这是一个全新的问题,但我真的很感谢你在这件事上的帮助。谢谢