Django 2 - Create html view

Nov 16, 2018 1 min read
Django 2 - Create html view


We'd like to create an html template to use in our web.


It's farely simple, just follow the steps:

  1. Create your new app: python startapp landingPage
  2. Register your app under in the main project folder (not in your newly created app) it looks like this:
    mysite/ (where mysite is the name you gave it when you wrote: django-admin startproject mysite)
    # the last part of the name (LandingpageConfig) will be located inside in your new app that you created.
  1. Register your templates directory. In your main project's folder, in, there is a line for TEMPLATES, make sure that your DIRS looks like this:
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
  1. In your newly created app directory (landingPage/), create a file called: and a folder called templates, inside templates folder, create a name with the same naming as your app (landingPage) -> this is convension and good practices, nothing more.
  1. On your -> landingPage/, write:
from django.shortcuts import render
from django.http import HttpResponse

def index(request):
    return render (request, 'landingPage/index.html')
  1. On your -> landingPage/, write:
from django.urls import path

from . import views

urlpatterns = [
    path('', views.index, name='index')

You should now have a working html page. Check it by running your app:
python runserver

I hope it helps

Great! Next, complete checkout for full access to ArturoFM.
Welcome back! You've successfully signed in.
You've successfully subscribed to ArturoFM.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info has been updated.
Your billing was not updated.