How to render template in Django

How to render template in Django

don’t forget to create templates directory in folder root.

│ ├───migrations
│ │ └───__pycache__
│ └───__pycache__
│ └───__pycache__
└───templates Source Code

<div>from django.shortcuts import render</div>
<div># Create your views here.</div>
<div>def index(request):</div>
<div>    context={</div>
<div>        "user":"Harlo",</div>
<div>    }</div>
<div>    return render(request, "index.html", context)</div>
</div> Source Code

<div>from django.contrib import admin</div>
<div>from django.urls import path</div>
<div>from core.views import index</div>
<div>urlpatterns = [</div>
<div>    path('admin/',,</div>
<div>    path('', index),</div>



<strong> Source Code Changes</strong>
<div>TEMPLATES = [</div>
<div>    {</div>
<div>        'BACKEND': 'django.template.backends.django.DjangoTemplates',</div>
<div>        'DIRS': [BASE_DIR/"templates"],</div>
<div>        'APP_DIRS': True,</div>
<div>        'OPTIONS': {</div>
<div>            'context_processors': [</div>
<div>                'django.template.context_processors.debug',</div>
<div>                'django.template.context_processors.request',</div>
<div>                'django.contrib.auth.context_processors.auth',</div>
<div>                'django.contrib.messages.context_processors.messages',</div>
<div>            ],</div>
<div>        },</div>
<div>    },</div>
Tony BB

TonyBB is a Coach , marketer, hypnotist and a founder of RSKVF Production who specializes in providing simple, affordable, and easy to use solutions for Life.

Click Here to Leave a Comment Below 0 comments

Leave a Reply: