I see Django has an auth URLfor logging in. How do I construct the login form?
I have a template that will have both login and register forms on it. My view `login_register` looks something like this:
def login_register(request, template="pages/login_register.html"):
'''
Display registration and login forms.
Process user registration.
Process user login.
'''
if request.method=="POST":
registration_form= UserCreationForm(request.POST)
if registration_form.is_valid():
registration_form.save()
username = registration_form.cleaned_data.get("username")
raw_password = registration_form.cleaned_data.get("password1")
user = authenticate(username=username, password=raw_password)
login(request, user)
return redirect(home_slug())
else:
registration_form = UserCreationForm()
return render(request, template, {"registration_form": registration_form})
The template for this view:
<div">
<h2>Log in</h2>
<form method="post">
{% csrf_token %}
{{ login_form.as_p }}
</form>
</div>
<div>
<h2>Register</h2>
<form method="post">
{% csrf_token %}
{{ registration_form.as_p }}
<button type="submit">Register</button>
</form>
</div>
It seems like `UserCreationForm` makes the register form. So how do I make the login form?