PythonCoder1981
PythonCoder1981

Reputation: 463

Django UserCreationForm not Submitting

I have django site that is am currently trying to create a user creation form for. I have following all the steps but something is not happening. When I click the button in my register form it does not submit anything. I also do not see a POST message in the terminal. When I go to the admin portal I also do not see what I have submitted.

Views.py

from django.shortcuts import render, redirect
from django.http import HttpResponseRedirect
from .models import StudentCourses
from .forms import StudentCoursesForm
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth import authenticate, login, logout

def registerPage(request):
    form = UserCreationForm()
    if request.method == 'POST':
        form = UserCreationForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('login')
        else:
            form = UserCreationForm()
    context = {'form': form}
    return render(request, 'Courses/register.html', context)

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Register</title>
</head>
<body>
    <h3>Register</h3>
    <form method="post">
        {% csrf_token %}
        {{ form.as_p }}

    </form>
    <button type="submit">Register</button>
</body>
</html>

Upvotes: 0

Views: 291

Answers (2)

Lars
Lars

Reputation: 1270

Try to use this :-

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Register</title>
</head>
<body>
    <h3>Register</h3>
    <form method="post">
        {% csrf_token %}
        {{ form.as_p }}
<button type="submit">Register</button>
    </form>
</body>
</html>

What have i changed:

I put <button type="submit">Register</button> inside .

Upvotes: 1

Andy
Andy

Reputation: 33

Put your button inside your form tags?

Upvotes: 1

Related Questions