python - The view didn't return an HttpResponse object. It returned None instead. Request Method: POST -


the problem appears when submit form. few days ago worked, changed nothing in code, fails. possible different module makes part of code crashed? traceback:

environment:

request method: post request url: http://127.0.0.1:8000/users/new/  django version: 1.7.3 python version: 3.4.0 installed applications: ('django.contrib.admin',  'django.contrib.auth',  'django.contrib.contenttypes',  'django.contrib.sessions',  'django.contrib.messages',  'django.contrib.staticfiles',  'mojblog',  'users') installed middleware: ('django.contrib.sessions.middleware.sessionmiddleware',  'django.middleware.common.commonmiddleware',  'django.middleware.csrf.csrfviewmiddleware',  'django.contrib.auth.middleware.authenticationmiddleware',  'django.contrib.auth.middleware.sessionauthenticationmiddleware',  'django.contrib.messages.middleware.messagemiddleware',  'django.middleware.clickjacking.xframeoptionsmiddleware')   traceback: file "/home/marta/django/djangovenv/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response   130.                                  % (callback.__module__, view_name))  exception type: valueerror @ /users/new/ exception value: view users.views.create didn't return httpresponse object. returned none instead. 

code:

from django.shortcuts import render, redirect django.http import httpresponse users.forms import usercreationform django.contrib.auth.models import user users.models import profile   def test(request):     return httpresponse('users!')   def create(request):     if request.method =="post":         new_user=user()         form = usercreationform(request.post, instance=new_user)         if form.is_valid():             new_user=form.save(commit=false)             new_user.is_active=false             new_user.save()             return redirect("users:new")      else:         form = usercreationform()         return render(request, 'users/create.html', {'form1': form})       # else:     #   return httpresponse("something")          def activate(request, key):      profile=profile.objects.get(secret=key)     user=profile.user     user.is_active=true     user.save()        return render(request, 'users/activate.html', {}) 

in create view, if request post form not valid, code not return anything.

rather have separate block, should use standard pattern:

if request.method =="post":     form = ...     if form.is_valid():         ...         return redirect(...) else:     form = ... return render(request, 'users/create.html', {'form1': form}) 

in case final return catches case, , re-renders form displays errors.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -