本文介绍了django-allauth返回错误“Reverse ... with arguments'()'和关键字arguments'{}'not found”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

凯文的答案解决了我的问题。原来allauth不支持命名空间,所以我不应该将这个引入到我的urls.py中。






原始POST :



我已经按照教程安装了django-allauth
https://github.com/pennersr/django-allauth



这里有一个非常基本的问题;在添加社交整合之前,无法获得基本的用户登录/输出页面。



通过导航到/ admin,我点击注销,所以我是不是登录的用户。



现在,当我访问 / accounts / login 我遇到这个错误



  No_reverseMatch at / accounts / login / 
使用参数'()'和关键字参数'{}反转'account_signup' ' 未找到。 0模式尝试:[]
请求方法:GET
请求URL:http:// localhost:5000 / accounts / login /
Django版本:1.6.5
异常类型:NoReverseMatch
异常值:
反向为'account_signup'与参数'()'和关键字参数'{}'未找到。 0模式尝试:[]

问题:我需要修改默认allauth views.py来解决这个问题?



如果相关,当我尝试通过shell


$ b时,同样的问题$ b

 (awe01)MoriartyMacBookAir13:getstartapp macuser $ python manage.py shell 
Python 2.7.5(默认,2014年3月9日,22:15:05)
>>>>来自django.core.urlresolvers import reverse
>>>> reverse('account_signup')
2014-09-30 16:54:29,256 boto [DEBUG]:使用配置文件中找到的访问密钥。
2014-09-30 16:54:29,256 boto [DEBUG]:使用配置文件中找到的秘密密钥。
追溯(最近的最后一次呼叫):
文件< console>,第1行,< module>
文件/Users/macuser/Dropbox/code/heroku/awe01/lib/python2.7/site-packages/django/core/urlresolvers.py,第532行,反向
return iri_to_uri( resolver._reverse_with_prefix(view,prefix,* args,** kwargs))
文件/Users/macuser/Dropbox/code/heroku/awe01/lib/python2.7/site-packages/django/core/urlresolvers .py,第452行,在_reverse_with_prefix
(lookup_view_s,args,kwargs,len(patterns),patterns))
NoReverseMatch:对于'account_signup'与参数'()'和关键字arguments'{ }' 未找到。 0模式尝试:[]

过去一小时已经google搜索,我不看看我失踪了它应该是开箱即用的,对吧?
我看到默认的base.html已经好像有了这行, {%从未来添加url%}



要确认,这里有一些摘要从我的主要settings.py(在文件夹共享教育/ settings.py)

  



#在项目中构建路径,如下所示:os.path.join(BASE_DIR,...)
import os
import dj_database_url
#from unipath import Path#,来自http://djangosteps.wordpress.com/2013/09/19/setting-up-django-allauth/
BASE_DIR = os.path .dirname(os.path.dirname(__ file__))


#安全警告:不要在生产中打开调试程序运行!
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []


TEMPLATE_CONTEXT_PROCESSORS =(
#来自http://django-allauth.readthedocs.org/en/latest/installation.html
#必需的allauth模板标签
django.core.context_processors.request,
#allauth具体的上下文处理器
allauth.account.context_processors.account,
allauth.socialaccount.context_processors.socialaccount,

#,这是由于错误消息
django.contrib.auth.context_processors.auth,




AUTHENTICATION_BACKENDS =(
#http://django-allauth.readthedocs .org / en / latest / installation.html
#需要通过Django管理员的用户名登录,不管`allauth`
django.contrib.auth.backends.ModelBackend,

#`allauth`具体的认证方法,如通过电子邮件登录
allauth.account.auth_backends.AuthenticationBackend,



#应用程序定义
#auth和allauth设置
LOGIN_REDIRECT_URL ='/'
SOCIALACCOUNT_QUERY_EMAIL = True
SOCIALACCOUNT_PROVIDERS = {
'facebook':{
#'AUTH_PARAMS':{'auth_type':'reauthenticate'},
'SCOPE':['email','publish_stream'],
'method':'js_sdk',#而不是'oauth2'
#'LOCALE_FUNC':'path.to.callable',
'VERIFIED_EMAIL':False
},
#'google':
#{'SCOPE':['https://www.googleapis.com/auth/userinfo.profile'],
#'AUTH_PARAMS':{'access_type':'在线'}},
#'linkedin':
#{'SCOPE':['r_emailaddress'],
#'PROFILE_FIELDS':['id',
#名字',
#'last-name',
#'email-address',
# 'picture-url',
#'public-profile-url']},

}
#SOCIALACCOUNT_ENABLED = True#@MM完全基于allauth urls .py和https://github.com/flashingpumpkin/django-socialregistration/issues/48

#allauth的更多设置
#http://django-allauth.readthedocs.org/ en / latest / configuration.html
ACCOUNT_PASSWORD_MIN_LENGTH = 5
#来自https://speakerdeck.com/tedtieken/signing-up-and-signing-in-users-in-django-with-的更多建议django-allauth
#ACCOUNT_AUTHENTICATION_METHOD =username

INSTALLED_APPS =(
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'storages',#http://django-storages.readthedocs.org/en/latest/
'polls',
'discover ,
'hello',
'upload',#from https://github.com/Widen/fine-uploader-server/blob/master/python/django-fine-uploader-s3/settings .py
'south',#http://south.readthedocs.org/en/latest/tutorial/part1.html
#Django网站框架需要
'django.contrib。网站',

'allauth',
'allauth.account',
'allauth.socialaccount',
#...包含您要启用的提供商:

'allauth.socialaccount.providers.facebook',

'allauth.socialaccount.providers.linkedin',

'allauth.socialaccount。 provider.twitter',



SITE_ID = 5#这对应于127.0.0.1:5000,因为我使用英雄的工头开始在本地运行东西
#不知道这个
#查看https://searchcode.com/codesearch/view/263279/
#我看了看表。从django_site中选择*,它显示awedify.org是id num 2
#awedify.org#原来只是单个字符,1
#来自http://django-allauth.readthedocs。 org / en / latest / installation.html

#from http://django-storages.readthedocs.org/en/latest/backends/amazon-S3.html
DEFAULT_FILE_STORAGE ='存储.backends.s3boto.S3BotoStorage'
#注意我还在STAICFILES_STORAGE中将此文件指定为此文件





#删除当尝试fineuploader
ADMINS =(
('Mark','[email protected]'),
#('您的姓名','[email protected]'),




MIDDLEWARE_CLASSES =(
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common。 CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.me ssages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',


ROOT_URLCONF ='shareducate.urls'

WSGI_APPLICATION ='shareducate.wsgi.application'


ALLOWED_HOSTS = ['*']

TEMPLATE_DIRS =(os.path.join(BASE_DIR,'templates' ,
'polls / templates / polls',
'upload / templates / upload',
#'polls / templates / polls',
'messing / templates / messing'
'discover / templates / discover',
'allauth / templates / allauth',
#或见http://djangosteps.wordpress.com/2013/09/19/settingupup -django-allauth /



#知道如何从各种来源导入模板的可调用列表。
TEMPLATE_LOADERS =(
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
#'django.template.loaders .eggs.Loader',



EMAIL_BACKEND ='django.core.mail.backends.console.EmailBackend'
#from http:// stackoverflow。 com / questions / 21563227 / django-allauth-example-errno-61-connection-refused

我有修改shareducate / urls.py
url(r'^ accounts /',include('allauth.urls',namespace ='allauth')),
,但我没有修改allauth文件夹内的任何内容



注意:通过转到/ admin,我可以以超级用户身份登录。然后确定,访问/帐户/登录将我重定向到root /,根据 settings.py
如果我发表了一行,#LOGIN_REDIRECT_URL ='/'然后确定我会根据 http:#获得定向到 / accounts / profile / //stackoverflow.com/a/16956071/870121



现在我已经注销了(我通过/ admin界面实现) ,当我访问 / accounts / login



时,allauth程序似乎无法处理我注意/allauth/templates/account/login.html看起来像这样...我还没有编辑它

  { %扩展account / base.html%} 

{%load i18n%}
{%load account%}
{%从未来%加载url}

{%block head_title%} {%trans登录%} {%endblock%}

{%block content%}

< h1& ; {%trans登录%}< / h1>

{%如果socialaccount.providers%}
< p> {%blocktrans with site.name as site_name%}请使用您现有第三方帐户的一个
登录。或者,< a href ={{signup_url}}>注册< / a> {{site_name}}帐户的
并在下面登录:{%endblocktrans%}< / p>

< div class =socialaccount_ballot>

< ul class =socialaccount_providers>
{%includesocialaccount / snippets / provider_list.htmlwith process =login%}
< / ul>

< div class =login-or> {%trans'或'%}< / div>

< / div>

{%includesocialaccount / snippets / login_extra.html%}

{%else%}
< p> {%blocktrans%}如果你尚未创建帐户,请
< a href ={{signup_url}}>注册< / a>第一。{%endblocktrans%}< / p>
{%endif%}

< form class =loginmethod =POSTaction ={%url'account_login'%}>
{%csrf_token%}
{{form.as_p}}
{%如果redirect_field_value%}
< input type =hiddenname ={{redirect_field_name}} value ={{redirect_field_value}}/>
{%endif%}
< a class =button secondaryActionhref ={%url'account_reset_password'%}> {%trans忘记密码? %}< / A>
< button class =primaryActiontype =submit> {%trans登录%}< / button>
< / form>

{%endblock%}

GUESS



(1)



根据这个答案 http://stackoverflow.com/a/13202435/870121
我想我可能需要修改这个allauth / accounts / views.py中的第109行

  84 class LoginView(RedirectAuthenticatedUserMixin,
85 AjaxCapableProcessFormViewMixin,
86 FormView):
87 form_class = LoginForm
88 template_name =account / login.html
89 success_url =无
90 redirect_field_name =next
91
92 def get_form_class(s​​elf):
93 return get_form_class(app_settings.FORMS,'login',self.form_class)
94
95 def form_valid(self,form):
96 success_url = self.get_success_url()
97 return form.login(self.request,redirect_url = success_url)
98
99 def get_success_url(self):
100#明确地通过? xt = URL优先级
101 ret =(get_next_redirect_url(self.request,
102 self.redirect_field_name)
103或self.success_url)
104 return ret
105
106 def get_context_data(self,** kwargs):
107 ret = super(LoginView,self).get_context_data(** kwargs)
108 signup_url = passthrough_next_redirect_url(self.request,
109 reverse(account_signup),
110 self.redirect_field_name)
111 redirect_field_value = self.request.REQUEST \
112 .get(self.redirect_field_name)
113 ret.update({signup_url:signup_url,
114site:Site.objects.get_current(),
115redirect_field_name:self.redirect_field_name,
116redirect_field_value redirect_field_val ue})
117 return ret
118
119 login = LoginView.as_view()

你看到它有 reverse(account_signup),没有额外的参数
我没有编辑这个,因为我认为allauth应该是工作开箱即用,通过修补来破解事物



该行在完整的追溯错误中突出显示。
追溯:

 文件/Users/macuser/Dropbox/code/heroku/awe01/lib/python2.7 /site-packages/django/core/handlers/base.pyin get_response 
112. response = wrapped_callback(request,* callback_args,** callback_kwargs)
文件/ Users / macuser / Dropbox / code /heroku/awe01/lib/python2.7/site-packages/django/views/generic/base.py在视图
69. return self.dispatch(request,* args,** kwargs)
文件/Users/macuser/Dropbox/code/heroku/awe01/getstartapp/allauth/account/views.py在调度
62. ** kwargs)
文件/ Users / macuser / Dropbox /code/heroku/awe01/lib/python2.7/site-packages/django/views/generic/base.py在dispatch
87. return handler(request,* args,** kwargs)
文件/Users/macuser/Dropbox/code/heroku/awe01/lib/python2.7/site-packages/django/views/generic/edit.py在get
161. return self.render_to_response(self .get_context_data(形式=表单))
文件/Users/macuser/Dropbox/code/heroku/awe01/getstartapp/allauth/account/views.pyin get_context_data
109. reverse(account_signup),
文件/Users/macuser/Dropbox/code/heroku/awe01/lib/python2.7/site-packages/django/core/urlresolvers.py反向
532. return iri_to_uri(resolver._reverse_with_prefix(view ,前缀,* args,** kwargs))
文件/Users/macuser/Dropbox/code/heroku/awe01/lib/python2.7/site-packages/django/core/urlresolvers.py在_reverse_with_prefix中
452.(lookup_view_s,args,kwargs,len(patterns),patterns)

(2)SITE_ID对于这个还是仅仅是为了社会整合而重要?



请告知从这里可能有意义的故障排除步骤。感谢提前,M

解决方案

让我提出一些调试提示,希望将来证明是有用的。 p>

当您看到特定的Django错误时,几乎总是意味着您的 urls.py 有问题。这种广泛使用的包具有影响这种基本用法的错误的可能性是相当遥远的,因此在这种情况下挖掘源代码可能是浪费的努力。



你说,你根据教程安装了 django-allauth ,但是当我将您的设置与我看到这个区别:



文档: r'^ accounts /',include('allauth.urls'))



你:(r'^ accounts /',include('allauth.urls',namespace ='allauth'))



所以看起来你的使用命名空间。



快速提取了,其中包装作者说明这个命名空间不受支持。



所以如果你摆脱了命名空间参数,一切都应该按预期工作。


EDIT:Kevin's answer below solved my issue. Turns out "allauth does not support namespaces" so I shouldn't have introduced this into my urls.py


ORIGINAL POST:

I have installed django-allauth exactly as per tutorialshttps://github.com/pennersr/django-allauth

I have a very basic problem here; can't get basic user login/out pages working even before I add in social integration.

By navigating to /admin, I clicked "log out", so I am not a logged in user.

Now when I visit /accounts/login I am met with this error

NoReverseMatch at /accounts/login/
Reverse for 'account_signup' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
Request Method: GET
Request URL:    http://localhost:5000/accounts/login/
Django Version: 1.6.5
Exception Type: NoReverseMatch
Exception Value:    
Reverse for 'account_signup' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

Question: Do I need to modify the default allauth views.py to solve this?

In case relevant, here's the same issue when I try via shell

(awe01)MoriartyMacBookAir13:getstartapp macuser$ python manage.py shell
Python 2.7.5 (default, Mar  9 2014, 22:15:05) 
>>> from django.core.urlresolvers import reverse
>>> reverse('account_signup')
2014-09-30 16:54:29,256 boto [DEBUG]:Using access key found in config file.
2014-09-30 16:54:29,256 boto [DEBUG]:Using secret key found in config file.
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/macuser/Dropbox/code/heroku/awe01/lib/python2.7/site-packages/django/core/urlresolvers.py", line 532, in reverse
    return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
  File "/Users/macuser/Dropbox/code/heroku/awe01/lib/python2.7/site-packages/django/core/urlresolvers.py", line 452, in _reverse_with_prefix
    (lookup_view_s, args, kwargs, len(patterns), patterns))
NoReverseMatch: Reverse for 'account_signup' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

Having been googling for the past hour, I don't see what I'm missing. It's supposed to work out of the box, right?I see the default base.html already seems to have the line, {% load url from future %}

To confirm, here are some extracts from my main settings.py (in folder shareducate/settings.py)

"""

"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
import dj_database_url
# from unipath import Path # that's from http://djangosteps.wordpress.com/2013/09/19/setting-up-django-allauth/
BASE_DIR = os.path.dirname(os.path.dirname(__file__))


# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []


TEMPLATE_CONTEXT_PROCESSORS = (
    # from http://django-allauth.readthedocs.org/en/latest/installation.html
    # Required by allauth template tags
    "django.core.context_processors.request",
    # allauth specific context processors
    "allauth.account.context_processors.account",
    "allauth.socialaccount.context_processors.socialaccount",

    # and this due to error message
    "django.contrib.auth.context_processors.auth",
)



AUTHENTICATION_BACKENDS = (
#     http://django-allauth.readthedocs.org/en/latest/installation.html 
    # 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",
)


# Application definition
# auth and allauth settings
LOGIN_REDIRECT_URL = '/'
SOCIALACCOUNT_QUERY_EMAIL = True
SOCIALACCOUNT_PROVIDERS = {
    'facebook': {
#        'AUTH_PARAMS': {'auth_type': 'reauthenticate'},
        'SCOPE': ['email', 'publish_stream'],
        'METHOD': 'js_sdk',  # instead of 'oauth2'
#        'LOCALE_FUNC': 'path.to.callable',
        'VERIFIED_EMAIL': False
    },
#     'google':
#         { 'SCOPE': ['https://www.googleapis.com/auth/userinfo.profile'],
#           'AUTH_PARAMS': { 'access_type': 'online' } },
#     'linkedin':
#       {'SCOPE': ['r_emailaddress'],
#        'PROFILE_FIELDS': ['id',
#                          'first-name',
#                          'last-name',
#                          'email-address',
#                          'picture-url',
#                          'public-profile-url']},
# 
}
# SOCIALACCOUNT_ENABLED = True # @MM completely made that up based on allauth urls.py and https://github.com/flashingpumpkin/django-socialregistration/issues/48

# more settings from allauth
# http://django-allauth.readthedocs.org/en/latest/configuration.html
ACCOUNT_PASSWORD_MIN_LENGTH = 5
# more suggestions from https://speakerdeck.com/tedtieken/signing-up-and-signing-in-users-in-django-with-django-allauth
# ACCOUNT_AUTHENTICATION_METHOD = "username"

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'storages', # http://django-storages.readthedocs.org/en/latest/
    'polls',
    'discover',
    'hello',
    'upload', # from https://github.com/Widen/fine-uploader-server/blob/master/python/django-fine-uploader-s3/settings.py
    'south', # http://south.readthedocs.org/en/latest/tutorial/part1.html
    # The Django sites framework is required
    'django.contrib.sites',

    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    # ... include the providers you want to enable:

    'allauth.socialaccount.providers.facebook',

    'allauth.socialaccount.providers.linkedin',

    'allauth.socialaccount.providers.twitter',

)

SITE_ID = 5 # this corresponds to "127.0.0.1:5000" since I use heroku's foreman start to run things locally
# Not sure about this
# check out https://searchcode.com/codesearch/view/263279/
# I looked at tables. Ran "select * from django_site and it showed that awedify.org was id num 2
# awedify.org # originally just the single character, 1
# that from http://django-allauth.readthedocs.org/en/latest/installation.html

# from http://django-storages.readthedocs.org/en/latest/backends/amazon-S3.html
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
# Note I also specify boto in STATICFILES_STORAGE later down this file





#    Added and removed when trying fineuploader
ADMINS = (
    ('Mark', '[email protected]'),
    # ('Your Name', '[email protected]'),
)



MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'shareducate.urls'

WSGI_APPLICATION = 'shareducate.wsgi.application'


ALLOWED_HOSTS = ['*']

TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'templates'),
         'polls/templates/polls',
         'upload/templates/upload',
         # 'polls/templates/polls',
         'messing/templates/messing',
         'discover/templates/discover',
         'allauth/templates/allauth',
        # or see http://djangosteps.wordpress.com/2013/09/19/setting-up-django-allauth/

)

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
#     'django.template.loaders.eggs.Loader',
)


EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' 
# from http://stackoverflow.com/questions/21563227/django-allauth-example-errno-61-connection-refused

I have modified shareducate/urls.pyurl(r'^accounts/', include('allauth.urls', namespace='allauth')),but I haven't modified anything inside the allauth folder

Note: by going to /admin, I can log in as the super user. Then sure enough, visiting /accounts/login redirected me to root /, as per settings.pyAnd if I commented out that line, # LOGIN_REDIRECT_URL = '/' then sure enough I would get directed to /accounts/profile/ as per http://stackoverflow.com/a/16956071/870121

Now that I am logged out though (which I achieved via the /admin interface), the allauth program doesn't seem to be able to deal with me when I visit /accounts/login

Note /allauth/templates/account/login.html looks like this... I haven't edited it at all

{% extends "account/base.html" %}

{% load i18n %}
{% load account %}
{% load url from future %}

{% block head_title %}{% trans "Sign In" %}{% endblock %}

{% block content %}

<h1>{% trans "Sign In" %}</h1>

{% if socialaccount.providers  %}
<p>{% blocktrans with site.name as site_name %}Please sign in with one
of your existing third party accounts. Or, <a href="{{ signup_url }}">sign up</a>
for a {{site_name}} account and sign in below:{% endblocktrans %}</p>

<div class="socialaccount_ballot">

  <ul class="socialaccount_providers">
    {% include "socialaccount/snippets/provider_list.html" with process="login" %}
  </ul>

  <div class="login-or">{% trans 'or' %}</div>

</div>

{% include "socialaccount/snippets/login_extra.html" %}

{% else %}
<p>{% blocktrans %}If you have not created an account yet, then please
<a href="{{ signup_url }}">sign up</a> first.{% endblocktrans %}</p>
{% endif %}

<form class="login" method="POST" action="{% url 'account_login' %}">
  {% csrf_token %}
  {{ form.as_p }}
  {% if redirect_field_value %}
  <input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}" />
  {% endif %}
  <a class="button secondaryAction" href="{% url 'account_reset_password' %}">{% trans "Forgot Password?" %}</a>
  <button class="primaryAction" type="submit">{% trans "Sign In" %}</button>
</form>

{% endblock %}

GUESS

(1)

Based on this answer http://stackoverflow.com/a/13202435/870121I think I may have to modify line 109 in this allauth/accounts/views.py

84 class LoginView(RedirectAuthenticatedUserMixin,
 85                 AjaxCapableProcessFormViewMixin,
 86                 FormView):
 87     form_class = LoginForm
 88     template_name = "account/login.html"
 89     success_url = None
 90     redirect_field_name = "next"
 91 
 92     def get_form_class(self):
 93         return get_form_class(app_settings.FORMS, 'login', self.form_class)
 94 
 95     def form_valid(self, form):
 96         success_url = self.get_success_url()
 97         return form.login(self.request, redirect_url=success_url)
 98 
 99     def get_success_url(self):
100         # Explicitly passed ?next= URL takes precedence
101         ret = (get_next_redirect_url(self.request,
102                                      self.redirect_field_name)
103                or self.success_url)
104         return ret
105 
106     def get_context_data(self, **kwargs):
107         ret = super(LoginView, self).get_context_data(**kwargs)
108         signup_url = passthrough_next_redirect_url(self.request,
109                                                    reverse("account_signup"),
110                                                    self.redirect_field_name)
111         redirect_field_value = self.request.REQUEST \
112             .get(self.redirect_field_name)
113         ret.update({"signup_url": signup_url,
114                     "site": Site.objects.get_current(),
115                     "redirect_field_name": self.redirect_field_name,
116                     "redirect_field_value": redirect_field_value})
117         return ret
118 
119 login = LoginView.as_view()

You see it has the reverse("account_signup") with no extra argumentsI have not edited this as I thought allauth was supposed to work out of the box and am relantant to break things by tinkering

That line is highlighted in the full traceback error.Traceback:

File "/Users/macuser/Dropbox/code/heroku/awe01/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  112.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/macuser/Dropbox/code/heroku/awe01/lib/python2.7/site-packages/django/views/generic/base.py" in view
  69.             return self.dispatch(request, *args, **kwargs)
File "/Users/macuser/Dropbox/code/heroku/awe01/getstartapp/allauth/account/views.py" in dispatch
  62.                                             **kwargs)
File "/Users/macuser/Dropbox/code/heroku/awe01/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch
  87.         return handler(request, *args, **kwargs)
File "/Users/macuser/Dropbox/code/heroku/awe01/lib/python2.7/site-packages/django/views/generic/edit.py" in get
  161.         return self.render_to_response(self.get_context_data(form=form))
File "/Users/macuser/Dropbox/code/heroku/awe01/getstartapp/allauth/account/views.py" in get_context_data
  109.                                                    reverse("account_signup"),
File "/Users/macuser/Dropbox/code/heroku/awe01/lib/python2.7/site-packages/django/core/urlresolvers.py" in reverse
  532.     return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
File "/Users/macuser/Dropbox/code/heroku/awe01/lib/python2.7/site-packages/django/core/urlresolvers.py" in _reverse_with_prefix
  452.                              (lookup_view_s, args, kwargs, len(patterns), patterns))

(2) Is SITE_ID important for this, or just for social integration?

Please advise of trouble-shooting steps which might make sense from here. Thanks in advance, M

解决方案

Let me present this answer with some debugging tips that hopefully will prove useful in the future.

When you see that particular Django error, it almost always means that something is wrong with your urls.py. The odds that such a widely-used package has a bug affecting such basic usage is pretty remote, so digging into the source code was probably wasted effort in this case.

You said that you installed django-allauth "exactly as per tutorials", but when I compare your setup to the documentation I see this difference:

Documentation: (r'^accounts/', include('allauth.urls'))

You: (r'^accounts/', include('allauth.urls', namespace='allauth'))

So it appears that something is wrong with your use of namespacing.

A quick Google search pulls up this issue, where the package author explains that namespacing isn't supported.

So if you get rid of the namespace argument, everything should work as expected.

这篇关于django-allauth返回错误“Reverse ... with arguments'()'和关键字arguments'{}'not found”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 21:10