我创建了一个用户注册表单,出于某种原因,first_name 和 last_name 字段存储在 (u'',) 中。我该如何防止这种情况?
views.py(不相关的东西省略了):
def register(request):
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.first_name=form.cleaned_data['first_name'],
user.last_name=form.cleaned_data['last_name'],
user.save()
userprofile, created = UserProfile.objects.get_or_create(user = user)
return HttpResponse("you have been successfully registered!")
模型.py:
class UserProfile(models.Model):
user = models.OneToOneField(User)
例如,我注册了一个名为 Joe Bruin 的用户。名称存储为 (u'Joe',) (u'Bruin',)。我认为 form.cleaned_data 出了点问题,但我不确定如何。