我有一个注册表单,提交后我收到以下错误。
_wrapped_view() 至少需要 1 个参数(给定 0)
它发生在我在view.py中实例化一个新的UserProfile对象时,即AppUserRegistration函数。
我正在把头撞在墙上。那里的错误信息根本没有多大帮助。
模型.py
class UserProfile(models.Model):
user = models.OneToOneField(User)
birthday = models.DateField(null=True, blank=True)
profession = models.CharField(max_length=100, null=True, blank=True)
created = models.DateTimeField()
modified = models.DateTimeField()
视图.py
from django.http import HttpResponseRedirect
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from django.shortcuts import render_to_response
from django.template import RequestContext
from AutoDIY.forms import RegistrationForm, LoginForm, UserProfileAboutForm
from AutoDIY.models import UserProfile
from django.contrib.auth import authenticate, login, logout
def AppUserRegistration(request):
if request.user.is_authenticated():
return HttpResponseRedirect('/')
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
first_name = form.cleaned_data.get('first_name')
last_name = form.cleaned_data.get('last_name')
username = form.cleaned_data.get('username')
email = form.cleaned_data.get('email')
password = form.cleaned_data.get('password')
user = User.objects.create_user(username=username,
email=email,
password=password)
user.first_name = first_name
user.last_name = last_name
user.save()
user_profile = UserProfile(user=user) # fails right here
...
注册.html
<form class="form-login form-wrapper form-medium" method="POST">
{% csrf_token %}
<h3 class="title-divider"><span>Sign Up</span>
<small>Already signed up? <a href="{% url login %}">Login here</a>.</small>
</h3>
{% if form.errors %}
<div class="alert alert-error">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Please correct the following fields:</strong>
<ul>
{% if form.first_name.errors %}<li>First name</li>{% endif %}
{% if form.last_name.errors %}<li>Last name</li>{% endif %}
{% if form.username.errors %}<li>Username</li>{% endif %}
{% if form.email.errors %}<li>Email address</li>{% endif %}
{% if form.password.errors %}<li>Password</li>{% endif %}
{% if form.password1.errors %}<li>Password Verification</li>{% endif %}
</ul>
</div>
{% endif %}
<h5>Account Information</h5>
{{ form.first_name }}
{{ form.last_name }}
{{ form.username }}
{{ form.email }}
{{ form.password }}
{{ form.password1 }}
<label class="checkbox">
<input type="checkbox" value="term">
I agree with the Terms and Conditions.
</label>
<button class="btn btn-primary" type="submit">Sign up</button>
</form>