pythonhtmldjangostatic-html

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


I have not figured out how I can present a website with pure HTML code and/or HTML + JavaScript + CSS.

I tried to load an HTML file that just says: Hello World.

I know I can do that with Django too, but later on, I want to display my website with CSS+JavaScript+HTML.

In the views file I run this code:

# Create your views here.
from django.http import HttpResponse
from django.template import Context, loader

def index(request):
    template = loader.get_template("app/index.html")
    return HttpResponse(template.render)

But the only thing the website displays is:


Solution

  • You are not calling the render method there, are you?

    Compare:

    template.render
    
    template.render()