Django - 'User'对象没有属性'get' - 检索密码

时间:2013-04-07 13:29:53

标签: python django django-models django-forms django-templates

我正在使用django 1.5,我尝试重置密码表单。所以我宣布:

我的模特:

class Profil(models.Model):
    user = models.OneToOneField(User)
    site_web = models.URLField(null=True, blank=True)
    avatar = models.ImageField(null=True, blank=True, upload_to="avatars/")
    signature = models.TextField(null=True, blank=True)

    def __unicode__(self):
        return "Profil de {0}".format(self.user.username)

我的表格有两个输入:

class ResetForm(PasswordResetForm):
new_password1 = forms.CharField(label="Mot de passe", widget=forms.PasswordInput(attrs={'class':'m-wrap', 'placeholder':'Mot de passe'}))
new_password2 = forms.CharField(label="Verification du mot de passe", widget=forms.PasswordInput(attrs={'class':'m-wrap', 'placeholder':'Verification du mot de passe'}))

我的urls.py:

urlpatterns = patterns('Profil.views',
)

urlpatterns += patterns('',
        url(r'^/?$',RedirectView.as_view(url='login/')),
        url(r'^login/?$','django.contrib.auth.views.login',
            {'template_name': 'Profil/login.html', 'authentication_form': LoginForm },
            name="login"),
        url(r'^logout/$','django.contrib.auth.views.logout_then_login', 
            name="logout"),
        url(r'^password_reset/$','django.contrib.auth.views.password_reset',
            {'email_template_name' : 'Profil/email/reset_passwd_email_template.html','subject_template_name': 'Profil/email/reset_passwd_email_subject.html'}, 
            name="reset_passwd"),
        url(r'^password_reset/done/$','django.contrib.auth.views.password_reset_done',
            { 'template_name' : "Profil/password_reset_done.html"},
            name='reset_done'),
        url(r'^reset/(?P<uidb36>[0-9A-Za-z]{1,13})-(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$','django.contrib.auth.views.password_reset_confirm',
            {'template_name' : 'Profil/password_reset_confirm.html', 'set_password_form': ResetForm },
            name='password_reset_confirm'),
        url(r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete',
            {'template_name' : 'Profil/password_reset_confirm.html'},
            name='password_reset_complete'),
    )

一切正常,但是当我提交表单重置密码时,我有一个错误:

AttributeError at /profil/reset/1-3gf-cfb3e30ff488d082a403/

'User' object has no attribute 'get'

Request Method:     POST
Request URL:    http://127.0.0.1:8000/profil/reset/1-3gf-cfb3e30ff488d082a403/
Django Version:     1.5.1
Exception Type:     AttributeError
Exception Value:    

'User' object has no attribute 'get'

Exception Location:     /usr/lib/python2.7/site-packages/django/forms/widgets.py in value_from_datadict, line 209
Python Executable:  /usr/bin/python2
Python Version:     2.7.3
Python Path:    

['/home/lolostates/workspace/Kolabe_py',
 '/usr/lib/python27.zip',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-linux2',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/lib/python2.7/site-packages',
 '/usr/lib/python2.7/site-packages/PIL',
 '/usr/lib/python2.7/site-packages/gtk-2.0',
 '/usr/lib/python2.7/site-packages/setuptools-0.6c11.egg-info']

Server time:    dim, 7 Avr 2013 15:07:14 +0200

我不明白为什么因为我正在使用用户的模型包含在Django上,并且所有认证功能也包含在django上......

感谢您的帮助,

Rergards, 卢瓦克。

编辑:正如评论所述,请在我的观点下面找到:

{% extends 'Layout/login.html' %}
{% load url from future %}

{% block title %} Kola.be - Initialisation du mot de passe {% endblock %}

{% block content %}

{% if validlink %}
<form class="form-vertical login-form" action="" method="post">
     {% csrf_token %}
      <h3 class="form-title">Re-initialisation</h3>
      <div class="control-group">
        <div class="controls">{{ form.new_password1.errors }}
          <div class="input-icon left">
            <i class="icon-lock"></i>
            {{ form.new_password1 }}
          </div>
        </div>
      </div>
      <div class="control-group">
        <div class="controls">{{ form.new_password2.errors }}
          <div class="input-icon left">
            <i class="icon-lock"></i>
            {{ form.new_password2 }}
          </div>
        </div>
      </div>
      <div class="form-actions">
        <input type="submit" class="btn green pull-right" value="Valider" />         
      </div>
    </form>
{% else %}

<h1>Re-initialisation du mot de passe échoué</h1>

<p>Le lien que vous avez utilisé a expiré, merci de faire une nouvelle demande de reset.</p>

{% endif %}
{% endblock %}

和堆栈跟踪:

Environment:


Request Method: POST
Request URL: http://127.0.0.1:8000/profil/reset/1-3gg-2b69dc12eab1b093dee2/

Django Version: 1.5.1
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'Client',
 'Profil',
 'django.contrib.admin')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  115.                         response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.7/site-packages/django/views/decorators/debug.py" in sensitive_post_parameters_wrapper
  69.             return view(request, *args, **kwargs)
File "/usr/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  89.         response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.7/site-packages/django/contrib/auth/views.py" in password_reset_confirm
  211.             if form.is_valid():
File "/usr/lib/python2.7/site-packages/django/forms/forms.py" in is_valid
  126.         return self.is_bound and not bool(self.errors)
File "/usr/lib/python2.7/site-packages/django/forms/forms.py" in _get_errors
  117.             self.full_clean()
File "/usr/lib/python2.7/site-packages/django/forms/forms.py" in full_clean
  272.         self._clean_fields()
File "/usr/lib/python2.7/site-packages/django/forms/forms.py" in _clean_fields
  281.             value = field.widget.value_from_datadict(self.data, self.files, self.add_prefix(name))
File "/usr/lib/python2.7/site-packages/django/forms/widgets.py" in value_from_datadict
  209.         return data.get(name, None)

Exception Type: AttributeError at /profil/reset/1-3gg-2b69dc12eab1b093dee2/
Exception Value: 'User' object has no attribute 'get'

0 个答案:

没有答案