Introduction
This article will focus on how to solve an error message exist in the Django-based framework web application. So, upon executing the command for running the Django-based framework web application, the following error will appear as follows :
The view myproject.views.contact didn't return an HttpResponse object. It returned None instead.
The following is the actual image where the error apparently exist :
This article has a connection with the previous article. The previous article with the title of ‘How to Solve Error Message crispy_forms.exceptions.CrispyError: |as_crispy_field got passed an invalid or inexistent field’ exist in this link. Before going further, below is the structure of the Django-based framework project :
C:\programming\python\myproject>tree . Folder PATH listing for volume Windows Volume serial number is 00000027 E003:3593 ├───myproject │ asgi.py │ forms.py │ models.py │ settings.py │ urls.py │ views.py │ wsgi.py │ __init__.py └───templates contact.html
So, the error location is in ‘myproject.views.contact’. That means, the error location exist in the folder of myproject within the ‘views.py’ file. More over, it exist in a function with the name of ‘contact’. According to that information, the following is the content of the ‘contact’ function inside the ‘views.py’ file :
def contact(request): contactForm = ContactForm context = {'form': contactForm} render(request, 'templates/contact.html', context)
Solution
The solution for the above problem is simple. The error is informing that the method of ‘contact’ in the ‘views.py’ file does not return an HttpResponse object. In order to solve that, just edit the method ‘contact’ and give the ‘return’ syntax. The following is the editable version of the views.py in the ‘contact’ function to solve the problem :
def contact(request): contactForm = ContactForm context = {'form': contactForm} return render(request, 'templates/contact.html', context)
After the editing process, the execution of the script will produce the following output :