0

編集: 画像を読み込めませんが、リンクは次のとおりです: https://plus.google.com/113782760013016224132/posts/3kcamT13yNP

ジャンゴを使用。これは私の最初の質問です。エラーが発生し続けます: Profile() が予期しないキーワード引数 'name' を取得しました。このエラーが発生する理由がよくわかりません。昨日は機能していましたが、今ではすべてが奇妙です。助けていただければ幸いです。

私のforms.pyは次のとおりです。

class RegistrationForm(ModelForm):
username    = forms.CharField(label=(u'User Name'))
email       = forms.EmailField(label=(u'Email Address'))
password    = forms.CharField(label=(u'Password'), widget=forms.PasswordInput(render_value=False))
verifyPass  = forms.CharField(label=(u'Verify Password'), widget=forms.PasswordInput(render_value=False))

class Meta:
    model = Profile
    exclude = ('user',)

def clean_username(self):
    username = self.cleaned_data['username']
    try:
            User.objects.get(username=username)
    except User.DoesNotExist:
            return username
    raise forms.ValidationError("That username is already taken, please select another username.")

def clean(self):
    password = self.cleaned_data.get('password', None)
    verifyPass = self.cleaned_data.get('verifyPass', None)

    if password != verifyPass:
        #self.cleaned_data['password'] != self.cleaned_data['verifyPass']:
        raise forms.ValidationError("Please try again, the passwords did not match.")
    return self.cleaned_data

ビュー.py:

def UserRegistration(request):
if request.user.is_authenticated():
    return HttpResponseRedirect('/profile')
if request.method == 'POST':
    form = RegistrationForm(request.POST)
    if form.is_valid():
        user = User.objects.create_user(username = form.cleaned_data['username'], email = form.cleaned_data['email'], password = form.cleaned_data['password'])
        user.save()
        users = Profile(user=user, name=form.cleaned_data['name'], date_of_birth=form.cleaned_data['date_of_birth'])
        users.save()
        return HttpResponseRedirect('/profile/')
    else:
        return render_to_response('register.html', {'form': form}, context_instance=RequestContext(request))
else:
    ''' user is not submitting the form, show them a blank registration form '''
    form = RegistrationForm()
    context = {'form': form}
    return render_to_response('register.html', context, context_instance=RequestContext(request))

def LoginRequest(request):
if request.user.is_authenticated():
    return HttpResponseRedirect('/profile/')
if request.method == 'POST':
    form = LoginUserForm(request.POST)
    if form.is_valid():
        username = form.cleaned_data['username']
        password = form.cleaned_data['password']
        users = authenticate(username = username, password = password)
        if users is not None:
            login(request, users)
            return HttpResponseRedirect('/profile/')
        else:
            return render_to_response('login.html', {'form' : form}, context_instance = RequestContext(request))
    else:
        return render_to_response('login.html', {'form' : form}, context_instance = RequestContext(request))
else:
    ''' user is not submitting the form, show the login form '''
    form = LoginUserForm()
    context = {'form': form}
    return render_to_response('login.html', context, context_instance=RequestContext(request))

def LogoutRequest(request):
logout(request)
return HttpResponseRedirect('/')

def Profile(request):
render_to_response('profile.html')

def home(request):
return render_to_response("home.html")

 class LoginUserForm(forms.Form):
username    = forms.CharField(label=(u'User Name'))
password    = forms.CharField(label=(u'Password'),    widget=forms.PasswordInput(render_value=False))

models.py:

class Profile(models.Model):
user            = models.OneToOneField(User)
date_of_birth   = models.DateField()
name            = models.CharField(max_length=100)

def __str__(self):
    return self.name
4

0 に答える 0