[Answered ]-Second static files directory in Django

2👍

You can fix this problem like this. Сhange this place of code

{% load static from staticfiles %}
<a href="{%static pic.path %}" class="gallery">Photo</a>

And write like this

{% load staticfiles %}

And you can add css in static dir and include css in template

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

0👍

To answer to your question follow the steps

Static

Create static files :
We create the static files to link the html files with this 3 files :
1/ CSS files
2/ JS files
3/ IMAGES files
..

How to create the static files ?

1/ Go to the project files and create a folder name it static.

static / CSS-JS-Images

2/ Go To the settings file and search for static after the STATIC_URL.

add this Two line:

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

STATICFILESDIRS = [ os.path.join(BASE_DIR, 'here you type the direction of the static file') ]

Make sur that you’re import the OS library

3/ finally you should collect static, to do that go on the terminal and add this code :

python manage.py collectstatic

here you find how to load static on the html file.

add this code on the top of the page :

{% load static %}

add this code To link CSS file with Html.

<link reel = 'stylesheet' href = " {% static 'dir of css file.css' %} "

May that help you.

Leave a comment