Even if I register as a member, I can't check it on the administration page, so I can't save it in the database, but I don't know where it went wrong.
Register.html code.
<html>
<head>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<link href="https://fonts.googleapis.com/css?family=Dosis&subset=latin,latin-ext" rel="stylesheet" type="text/css">
<title>Regitser With PAM</title>
</head>
<body>
<h1>Register With PAM</h1>
{% {% if registered %}
<strong>Thank you for registering!</strong>
<a href = "/mysite">Return to MainPage.</a><br />
{% {% else %}
<strong>Register here!</strong><br />
<form id = "user_form" method = "post" action = "/mysite/register/" enctype = "multipar/form-date">
{% {% csrf_token %}
{{ {{ user_form.as_p }}
{{ {{ profile_form.as_p}}
<input type = "submit" name "submit" value = "Register" />
</form>
{% {% endif %}
</body>
</html>
models.py
class UserProfile(models.Model):
user = models.OneToOneField(User)
schoolid = models.PositiveIntegerField(primary_key=True, validators=[MaxValueValidator(5)])
phone_number = models.PositiveIntegerField(primary_key=True, validators=[MaxValueValidator(11)])
def __str__(self):
return self.user,username
views.py
def register(request):
context = RequestContext(request)
registered = False
if request.method == 'POST':
user_form = UserForm(data=request.POST)
profile_form = UserProfile(data=request.POST)
if user_form.is_valid() and profile_form.is_valid():
user = user_form.save()
user.set_password(user.password)
user.save()
profile = profile_form.save(commit=False)
profile.user = user
profile.save()
registered = True
else:
print(user_form.errors, profile_form.errors)
else:
user_form = UserForm()
profile_form = UserProfileForm()
return render_to_response(
'mysite/register.html',
{'user_form':user_form, 'profile_form':profile_form, 'registered': registered}, context)
Execution screen
However, even if you press register and register, if you go to the admin page...
If you register there, it will come up with 404 error
If you look at the subscription page, the address is /register, but the action is
in HTML/mysite/register/ Yes
Just change it to "/register" or ""
© 2024 OneMinuteCode. All rights reserved.