Home » Django

How to use Static Data in Django?

Here, we are going to learn through an example, how to use static data in Django web application framework?
Submitted by Pankaj Singh, on November 07, 2018

Static Data means those data items that we cannot want to change, we want to use them as it is like audio, video, images, files etc.

Here, are the steps to create an application that will demonstrate the use of static data in Django:

Step 1: Create a Sandbox, Activate it, Install Django and Create Sample Project

Creating Sandbox

Use static data in django 1

Activating it

Use static data in django 2

Installing Django

Use static data in django 3

Creating Sample Project [myapp]

Use static data in django 4

Project Structure [myapp]

Use static data in django 5

Step 2: Add a new folder (i.e. static) in root location (i.e. myapp folder[outer])

Use static data in django 6

Step 3: Add Static Data (audio, videos etc) inside static folder

Use static data in django 7

Step 4: Add static folder path to settings.py of admin app (i.e. myapp[inner])

Use static data in django 8
Use static data in django 9

Step 5: Add a new folder templates for HTML Templates in project folder (i.e. myapp[outer])

Use static data in django 10

Step 6: Add templates location to setting.py in admin app (i.emyapp[inner])

Use static data in django 11
Use static data in django 12

Step 7: Add a master page (base.html) in templates folder

Use static data in django 13

Different sections of Body Tag of base.html

Use static data in django 14
Use static data in django 15
Use static data in django 16
Use static data in django 17

Step 8: Now Add child pages (i.e. index.html, audio.html, video.html, image.html, pdf.html)

Use static data in django 18

Index.html

Use static data in django 19

Audio.html

Use static data in django 20

Video.html

Use static data in django 21

Image.html

Use static data in django 22

Pdf.html

Use static data in django 23

Step 9: Add a controller file (views.py) to manage views in admin app (i.e. myapp[inner])

Use static data in django 24

Step 10: Add controller actions (functions) to views.py to manage requests.

Use static data in django 25

Step 11: Add new url to urls.py in admin app (i.e. myapp[inner])

Use static data in django 26
Use static data in django 27

Step 12: Run the Server

Use static data in django 28
Use static data in django 29

Step 13: Open Browser and type http://127.0.0.1:8000

Use static data in django 30

Use static data in django 31

Use static data in django 32

Use static data in django 33



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.