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:
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')