I'm trying to add inputs on my application where a user can put in their "age", "city", and "state". It already worked for "first_name", "last_name", and "email", but when I added these fields I got this error thrown at me.
Person Model:
class Person(models.Model):
""" The model which defines a user of the application. Contains important
information like name, email, city/state, age, etc """
user = models.OneToOneField(User)
first_name = models.CharField(max_length=200, null=True)
last_name = models.CharField(max_length=200, null=True)
email = models.CharField(max_length=200, null=True)
city = models.CharField(max_length=200, null=True)
state = models.CharField(max_length=200, null=True)
age = models.CharField(max_length=50, null=True)
View for creating an account:
def create_account(request):
# function to allow a user to create their own account
if request.method == 'POST':
# sets a new user and gives them a username
new_user = User(username = request.POST["username"],
email=request.POST["email"],
first_name=request.POST["first_name"],
last_name=request.POST["last_name"],
age=request.POST["age"],
city=request.POST["city"],
state=request.POST["state"])
# sets an encrypted password
new_user.set_password(request.POST["password"])
new_user.save()
# adds the new user to the database
Person.objects.create(user=new_user,
first_name=str(request.POST.get("first_name")),
last_name=str(request.POST.get("last_name")),
email=str(request.POST.get("email")),
age=str(request.POST.get("age")),
city=str(request.POST.get("city")),
state=str(request.POST.get("state")))
new_user.is_active = True
new_user.save()
return redirect('../')
else:
return render(request, 'polls/create_account.html')
Any ideas why I get this error?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…