Getting ValueError when using UserCreationForm

21 Views Asked by At

Hello to this awesome community.

Im trying to achieve a successful user registration for a CRUD.

What am I doing wrong?

But I can't stop from getting this error: The view dashboard.views.crearUsuario didn't return an HttpResponse object. It returned None instead.

Here Is the code on Views:

def crearUsuario(request):
    if request.method == 'POST':
        form = UserCreationForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect ('listado_user')
        else:
            return HttpResponse('Algo salio mal')
    else:
        form = UserCreationForm()
        return render(request, 'usuarios/crear_usuario.html', {'form': form})

Code in crear_usuario.html:

{% extends "../index_master.html" %}

{% block content %}

<div class="right_col" role="main">

    <form method="POST">{% csrf_token %}
      {{form.as_p}}   
    <input type="submit" value="Guardar">
    </form>
     
</div>
{% endblock %}

I created an "Users" app, but after watching some videos, I realized django has this app by default, which everyone seems to be using. Thanks in advance.

Im trying to get the default UserCreationForm to work, so from there I could elaborate a more detailed Registration form... If its considered important, Users are meant to be created by the staff.

0

There are 0 best solutions below