Azad Rasul
SmartRS

SmartRS

13- Create static files

Azad Rasul's photo
Azad Rasul
·May 14, 2022·

1 min read

Subscribe to my newsletter and never miss my upcoming articles

Listen to this article

Static files are necessary files to render the complete web page such as images, JavaScript, or CSS.

First, create a directory called static in your polls directory: Sublime Text> select polls> right click> New Folder> Name it "static".

Then, create another directory called polls and within that create a file called style.css. Put the following code in that stylesheet (polls/static/polls/style.css):

li a {
    color: green;
}

Next, add the following at the top of polls/templates/polls/index.html:

{% load static %}

<link rel="stylesheet" type="text/css" href="{% static 'polls/style.css' %}">

Reload localhost:8000/polls and you should see that the question links are green.

Then, create an images subdirectory in the polls/static/polls/ directory. Inside this directory, put an image called background. In other words, put your image in polls/static/polls/images/background.jpg

Then, add to your stylesheet (polls/static/polls/style.css):

body {
    background: white url("images/background.jpg") no-repeat;
}

Reload localhost:8000/polls and you should see the background loaded in the top left of the screen.

image.png

For more details about the Django basic tutorial, go to the main source of this tutorial: docs.djangoproject.com/en/4.0/intro/tutoria..

 
Share this