0

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.

2
  • The first else statement should be return HttpResponse('Algo salio mal'). You forgot the keyword return. Commented Dec 23, 2023 at 2:27
  • Hello! You were right! That was my bad, but the user still not being created... Is there anything else I could be doing wrong? Commented Dec 23, 2023 at 2:47

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.