How to return a static HTML file as a response in Django?

If your file isn’t a django template but a plain html file, this is the easiest way:

from django.shortcuts import render_to_response

def index (request):
    return render_to_response('app/index.html')

UPDATE 10/13/2020:

render_to_response was deprecated in Django 2.0 and removed in 3.0, so the current way of doing this is:

from django.shortcuts import render

def index (request):
    return render(request, 'app/index.html')

Leave a Comment

tech