CreateUser not showing errors

I am trying to create a user and profile at the same time but sending two forms to a template - like this:

@block_authenticated_user
def create_profile(request):
    user_form = CreateUserForm()
    profile_form = CreateProfileForm()
    if request.method=="POST":
        user_form = CreateUserForm(request.POST)
        profile_form = CreateProfileForm(request.POST)
        if user_form.is_valid() and profile_form.is_valid():
            # User = user_form.save()
            # Profile = profile_form.save()
            username = user_form.cleaned_data.get('username')
            messages.success(request, f'Profile was created for {username}' )
            return redirect('login')
    context = {'user_form': user_form, 'profile_form': profile_form}
    return render(request, 'profiles/create_profile.html', context)

It appears to work, but when the forms are invalid i am getting no error messages.

The html includes:

{% if form.errors %}
<div class="alert alert-danger">
    {% for key, value in form.errors.items %}
        {{ value.as_text }}
    {% endfor %}
</div>
{% endif %}


{% for message in messages %}
    <p id="messages">{{message}}</p>
{% endfor %}

Any suggestions. Is this a totally misguided way of doing things?
thanks

When you are creating two different forms to be rendered in a single HTML form on a page, you need to use the prefix attribute on one (or both) of those forms to ensure no field conflicts between the two forms.

Regarding the error message situation, you have not included enough of the template for us to determine a possible or likely cause of that issue.

Thank you. The full template is as follows:


{% extends 'profiles/main.html' %}
{% block content %}

<h1>Please create a profile</h1>

<form method='POST'>
     {% csrf_token %}
     <p>{{user_form.username.label}}</p>
     <p>{{user_form.username}}</p>
     <ul>
        <li>Required. 150 characters or fewer.</li>
        <li>Letters, digits and @/./+/-/_ only.</li>
     </ul>
     <p>{{user_form.password1.label}}</p>
     <p>{{user_form.password1}}</p>
     <p>{{user_form.password2.label}}</p>
     <p>{{user_form.password2}}</p>
    <ul>
        <li>Your password can’t be too similar to your other personal information.</li>
        <li>Your password must contain at least 8 characters.</li>
        <li>Your password can’t be a commonly used password.</li>
        <li>Your password can’t be entirely numeric.</li>
    </ul>
     <p>{{user_form.email.label}}</p>
     <p>{{user_form.email}}</p>

    <hr>
        <p>{{ profile_form.title.label }}</p>
        <p>{{ profile_form.title }}</p>
        <p>{{ profile_form.first_name.label }}</p>
        <p>{{ profile_form.first_name }}</p>
        <p>{{ profile_form.last_name.label }}</p>
        <p>{{ profile_form.last_name }}</p>
        <p>{{ profile_form.address1.label }}</p>
        <p>{{ profile_form.address1 }}</p>
        <p>{{ profile_form.address2.label }}</p>
        <p>{{ profile_form.address2 }}</p>
        <p>{{ profile_form.addresss3.label }}</p>
        <p>{{ profile_form.addresss3 }}</p>
        <p>{{ profile_form.postcode.label }}</p>
        <p>{{ profile_form.postcode }}</p>
        <p>{{ profile_form.phone.label }}</p>
        <p>{{ profile_form.phone }}</p>
        <p>{{ profile_form.email.label }}</p>
        <p>{{ profile_form.email }}</p>

    <input class='btn btn-secondary' type='submit' name='Submit'/>
</form>


{% if form.errors %}
<div class="alert alert-danger">
    {% for key, value in form.errors.items %}
        {{ value.as_text }}
    {% endfor %}
</div>
{% endif %}


{% for message in messages %}
    <p id="messages">{{message}}</p>
{% endfor %}

<p>Already have an account? <a href="{% url 'login' %}" class="ml-2">Login</a></p>

{% endblock %}

I don think there is a conflict because i am referring to each forms fields by using the name of the form.
But i will look further at the link you gave, thanks

As I submit that message i think i see the problem. The errors are ‘form’ errors and presumably should be ‘user_form’ or ‘profile_form’ errors.

yes, that sorted it, … still learning

Side note, the conflicts I’m referring to are what happens in Django during form processing, not what is rendered in the html. If both forms have a field with the same name, that would create a conflict in Django

Thank you, i will check that too