Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

ValueError at /users/register/ The view users.views.register didn't return an HttpResponse object. It returned None instead

I am getting this error ValueError at /users/register/ The view users.views.register didn’t return an HttpResponse object. It returned None instead.

I am using Django to complete the registration form, however I was unable to eliminate this problem.

def register(request):
      if request.method == 'POST':
            user_form = UserRegistrationForm(request.POST)
            if user_form.is_valid():
                  new_user = user_form.save(commit=False)
                  new_user.set_password(user_form.cleaned_data['password'])
                  new_user.save()
                  return render(request,'users/register_done.html')
            else:
                  user_form = UserRegistrationForm()
            return render(request,'users/register.html',{'user_form':user_form})

This is my views.py file made a register function with the return render.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

path('register/',views.register,name='register'),

this is urls py

Is there any other solution to come over
My result Output

I am expecting the solution for my problem

>Solution :

You also need to display error messages like if user already exits or password is empty or too-small.

Now the return statement is outside of if statement.

def register(request):

    if request.method == 'POST':
        user_form = UserRegistrationForm(request.POST)
        if user_form.is_valid():
                new_user = user_form.save(commit=False)
                new_user.set_password(user_form.cleaned_data['password'])
                new_user.save()
                return render(request,'users/register_done.html')
        else:
                user_form = UserRegistrationForm()
    
    return render(request,'users/register.html',{'user_form':user_form})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading