M
M
MalikDeveloper20772020-02-21 11:44:43
Django
MalikDeveloper2077, 2020-02-21 11:44:43

Static in Django how?

I have this code in settings.py

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

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')


I have a base template in the project's root templates folder and others already in the apps themselves.
I want to connect a separate file to the base template and connect other files separately to applications.
Project structure:
-proj
|-- proj
|---- settings.py
|---- and others
|-- app
|---- static (apps)
|-------- app
|-- ---------- css
|---------------- style.css
|---- templates (applications)
|--------- app
|------------- list.html
|---- views.py and others

|--static (root for base template)
|---- css
|-------- style.css

|--templates (root with base template)
|---- base.html

To base.html
{% load static %}
<link rel="stylesheet" href="{% static 'css/style.css' %}">
{% block links %}{% endblock %}


In list.html (template in app)
{% extends 'base.html' %}
{% load static %}
{% block links %}
<link rel="stylesheet" href="{% static 'css/style.css' %}">
{% endblock %}


And the static is not connected. What is the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir, 2020-02-21
@Realmixer

If you are running the site in via runserver, then you need to configure the distribution of statics in development mode .
If you run for real through uwsgi/gunicorn+nginx, then you need to configure nginx to distribute statics.
Well, do not forget about the team collectstatic.

K
Konstantin Malyarov, 2020-02-21
@Konstantin18ko

proj
app
static Move static
up a folder.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question