How to render template in Django
How to render template in Django
don’t forget to create templates directory in folder root.
├───core
│ ├───migrations
│ │ └───__pycache__
│ └───__pycache__
├───school
│ └───__pycache__
├───static
└───templates
views.py Source Code
from django.shortcuts import render # Create your views here. def index(request): context={ "user":"Harlo", } return render(request, "index.html", context)
urls.py Source Code
from django.contrib import admin from django.urls import path from core.views import index urlpatterns = [ path('admin/', admin.site.urls), path('', index), ]
settings.py Source Code Changes TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [BASE_DIR/"templates"], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ]