Reputation: 3
I am trying to make my new form and in that process i have encountered this issue of The view myapp.views.contact didn't return an HttpResponse object. It returned None instead.Please help me out
The problem is in return render function and have no clue of how solve this HttpResponse error
from django.shortcuts import render
from django.http import HttpResponse
from .forms import ContactForm,SnippetForm
def contact(request):
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid():
name= form.cleaned_data['name']
email=form.cleaned_data['email']
print(name,email)
form = ContactForm()
return render(request,'form.html',{'form':form})
def snippet_detail(request):
if request.method == 'POST':
form = SnippetForm(request.POST)
if form.is_valid():
print("VALID")
form = SnippetForm()
return render(request,'form.html',{'form': form})
#form.save()
The error message is in the browser and the question is itself a error message.
Upvotes: 0
Views: 1050
Reputation: 5854
There might be form error
You need to handle form error case.
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid():
name= form.cleaned_data['name']
email=form.cleaned_data['email']
print(name,email)
form = ContactForm()
return render(request,'form.html',{'form':form})
else:
return render(request,'form.html',{'form':form})
else:
form = ContactForm()
return render(request,'form.html',{'form':form})
hope it helps. refer this
Upvotes: 2