Design a site like this with
Get started

Django – Templates Basic

Lets see how to respond with an html in django. Till now we have seen how to respond to a rest call with a json response. But we will also need to respond to a request with an html/css/javascript. Lets create a small django app to demonstrate the same.


Step 1

Open command terminal and create a directory “TemplateDjangoProject” and navigate into that project

Step 2

First install Django with command “pip install django”

Step 3

Create a project with command “django-admin startporject testproject . “

Step 4

Now create app with command “python testapp”

Step 5

Add the newly created app in the file of the testproject folder under the installed_apps array as below to register our new app

Step 6

Now, create a new folder templates under the app testapp folder and create index.html file with content as below

Step 7

Create a function in the file of the app testapp as below

Step 8

update the if not present) file as below. Here we are mapping our url to the function we created in the file in the previous step

Step 9

Now update the of the our testproject to include the urls created in our app.

Step 10

We are done. Now run the server executing the command “python runserver” and then navigate to the deploy url to see below response from the server


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: