ValueError at / The view leads.views.home_page didn't return an HttpResponse object. It returned None instead python django template error how to fix

Issue

ValueError at /
The view leads.views.home_page didn’t return an HttpResponse object. It returned None instead.

this is my code:

views.py:

from django.shortcuts import render
from django.http import HttpResponse

def home_page(request):
    
    # return HttpResponse('Hello world')
    render(request, 'leads/home_page.html')

and here’s the urls.py:

from django.contrib import admin
from django.urls import path

from leads.views import home_page

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', home_page),
]

and here’s the template:

enter image description here

Solution

The issue is here

def home_page(request):
    render(request, 'leads/home_page.html')

render combines a given template with a given context dictionary and returns an HttpResponse object with that rendered text. So you have to return this HttpResponse back from view.

def home_page(request):
    return render(request, 'leads/home_page.html')

Answered By – Abdul Niyas P M

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published