2016-07-20 29 views
0

DjangoとPythonを初めて使用しています。私はデフォルトのAuthenticationFormにいくつかの問題があるので、私はこの質問に従った:How do I extend the Django "login" form?AUTHENTICATIONFORMをオーバーライドする際に 'WSGIRequest'オブジェクトに属性 'get'エラーがありません

from .forms import LoginForm 

urlpatterns = [ 
    # url(r'^login/$', views.user_login, name='login'), 
    url(r'^login/$', auth_views.login, {'authentication_form': LoginForm}, name='login'), 
    url(r'^logout/$', auth_views.logout, name='logout'), 
    url(r'^logout-then-login/$', auth_views.logout_then_login, name='logout_then_login'), 
    url(r'^$', views.dashboard, name='dashboard'), 

編集:

Traceback: 

File "C:\Users\Jorj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\handlers\base.py" in get_response 
    174.      response = self.process_exception_by_middleware(e, request) 

File "C:\Users\Jorj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\handlers\base.py" in get_response 
    172.      response = response.render() 

File "C:\Users\Jorj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\template\response.py" in render 
    160.    self.content = self.rendered_content 

File "C:\Users\Jorj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\template\response.py" in rendered_content 
    137.   content = template.render(context, self._request) 

File "C:\Users\Jorj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\template\backends\django.py" in render 
    95.    return self.template.render(context) 

File "C:\Users\Jorj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\template\base.py" in render 
    206.      return self._render(context) 

File "C:\Users\Jorj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\template\base.py" in _render 
    197.   return self.nodelist.render(context) 

File "C:\Users\Jorj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\template\base.py" in render 
    992.     bit = node.render_annotated(context) 

File "C:\Users\Jorj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\template\base.py" in render_annotated 
    959.    return self.render(context) 

File "C:\Users\Jorj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\template\loader_tags.py" in render 
    173.   return compiled_parent._render(context) 

File "C:\Users\Jorj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\template\base.py" in _render 
    197.   return self.nodelist.render(context) 

File "C:\Users\Jorj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\template\base.py" in render 
    992.     bit = node.render_annotated(context) 

File "C:\Users\Jorj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\template\base.py" in render_annotated 
    959.    return self.render(context) 

File "C:\Users\Jorj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\template\loader_tags.py" in render 
    69.     result = block.nodelist.render(context) 

File "C:\Users\Jorj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\template\base.py" in render 
    992.     bit = node.render_annotated(context) 

File "C:\Users\Jorj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\template\base.py" in render_annotated 
    959.    return self.render(context) 

File "C:\Users\Jorj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\template\base.py" in render 
    1043.    output = self.filter_expression.resolve(context) 

File "C:\Users\Jorj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\template\base.py" in resolve 
    709.     obj = self.var.resolve(context) 

File "C:\Users\Jorj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\template\base.py" in resolve 
    850.    value = self._resolve_lookup(context) 

File "C:\Users\Jorj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\template\base.py" in _resolve_lookup 
    913.        current = current() 

File "C:\Users\Jorj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\forms\forms.py" in as_p 
    281.    errors_on_separate_row=True) 

File "C:\Users\Jorj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\forms\forms.py" in _html_output 
    180.   top_errors = self.non_field_errors() # Errors that should be displayed above all fields. 

File "C:\Users\Jorj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\forms\forms.py" in non_field_errors 
    289.   return self.errors.get(NON_FIELD_ERRORS, self.error_class(error_class='nonfield')) 

File "C:\Users\Jorj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\forms\forms.py" in errors 
    153.    self.full_clean() 

File "C:\Users\Jorj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\forms\forms.py" in full_clean 
    362.   self._clean_fields() 

File "C:\Users\Jorj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\forms\forms.py" in _clean_fields 
    374.     value = field.widget.value_from_datadict(self.data, self.files, self.add_prefix(name)) 

File "C:\Users\Jorj\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\forms\widgets.py" in value_from_datadict 
    231.   return data.get(name) 

Exception Type: AttributeError at /Home/login/ 
Exception Value: 'WSGIRequest' object has no attribute 'get' 

これは私のforms.py

from django import forms 
from django.contrib.auth.models import User 
from django.contrib.auth.forms import AuthenticationForm 
from .models import Profile 


class LoginForm(AuthenticationForm): 
    error_messages = { 
     'invalid_login': ("Please enter a correct %(username)s and password. " 
          "Note that both fields may be case-sensitive."), 
     'inactive': ("This account is inactive."), 
    } 


class UserEditForm(forms.ModelForm): 
    class Meta: 
     model = User 
     fields = ('first_name', 'last_name', 'email') 

とurls.pyが --'WSGIRequest' object has no attribute 'get'--

です:さて、私は言う、いくつかのエラーを取得していますこれはview.py:

です
from django.shortcuts import render 
from .forms import UserRegistrationForm, UserEditForm, ProfileEditeForm 
from django.contrib.auth.decorators import login_required 
from .models import Profile 
from django.contrib import messages 


@login_required 
def dashboard(request): 
    return render(request, 'account/dashboard.html', {'section': 'dashboard'}) 


@login_required 
def edit(request): 
    if request.method == 'POST': 
     user_form = UserEditForm(instance=request.user, data=request.POST) 
     profile_form = ProfileEditeForm(instance=request.user.profile, 
             data=request.POST, 
             files=request.FILES) 
     if user_form.is_valid() and profile_form.is_valid(): 
      user_form.save() 
      profile_form.save() 
      messages.success(request, 'Profile updated successfully') 
     else: 
      messages.error(request, 'Error updating your profile') 
    else: 
     user_form = UserEditForm(instance=request.user) 
     profile_form = ProfileEditeForm(instance=request.user.profile) 
    return render(request, 'account/edit.html', {'user_form': user_form, 'profile_form': profile_form}) 


def register(request): 
    if request.method == 'POST': 
     user_form = UserRegistrationForm(request.POST) 
     if user_form.is_valid(): 
      new_user = user_form.save(commit=False) 
      new_user.set_password(user_form.cleaned_data['password']) 
      new_user.save() 
      pofile = Profile.objects.create(user=new_user) 
      return render(request, 'account/register_done.html', {'new_user': new_user}) 

    else: 
     user_form = UserRegistrationForm() 
    return render(request, 'account/register.html', {'user_form': user_form}) 

スーパークラスを拡張する際に何か忘れましたか?

+1

あなたは完全なトレースバックを投稿できますか? – jape

+0

ok私はそれらを追加しました – aliopalopina

+0

あなたもあなたのビューを投稿してくださいできますか? – jape

答えて

0

私は解決しました、私はLoginFormiに私のフォーム名を変更し、エラーはなくなりました。多分djangoのバグ

関連する問題