Registration with UserCreationForm

Hello community :slight_smile:
I’m (trying) to build a simple login, with the Django default user. Unfortunately it doesn’t work :confused:

I migrated a SQLite database - created a SuperUser which I find on the database.

If I go to my register.html and enter username + password - nothing happens. Even if I enter two different passwords, no error message. I assumed Django was allowed to die - am I wrong here? Also, the user is not saved in the database (auth_user). Also, I’m amazed that the form data is displayed in the URL, like a GET request.

Can you help me?

def register_view(request):
    register_form = UserCreationForm()
    if request.method == "POST":
        register_form = UserCreationForm(request.POST)
        if register_form.is_valid():
            username = register_form.cleaned_data["username"]
            password = register_form.cleaned_data["password1"]
            user = authenticate(request, username=username, password=password)
            if user:
                login(request, user)
    return render(request, "user_interface/register.html", {"register_form": register_form})


<!DOCTYPE html>
<html lang="de">
        <meta charset="UTF-8">
        <title>{% block title %} BlogPost {% endblock title %}</title>

        {% if request.user.is_authenticated %}
        <p> Hallo {{ request.user.username }}!</p>
        {% else %}
        <a href="{% url 'user_interface:login' %}">Login</a>
        <a href="{% url 'user_interface:register' %}">Account anlegen</a>
        {% endif %}
        {% block authForm %}
        {% endblock %}


{% extends 'user_interface/base.html' %}

{% block title %} BlogPost - Auccount anlegen {% endblock title %}

{% block authForm %}
<form methode="post" action="">
    {% csrf_token %}
    {{ register_form.as_p }}
    <button type="submit">Account anlegen</button>
{% endblock %}

app_name = "user_interface"
urlpatterns = [
    path('', views.index, name="index"),
    path('login/', views.login_view, name="login"),
    path('register/', views.register_view, name="register"),

Your register_view isn’t doing anything upon either a valid or invalid form other than just re-rendering the current page.

Review the docs and example at login() to see how the flow should be handled.

Also, you have a typo in your template - the form tag should be method and not methode.