Answer the question
In order to leave comments, you need to log in
Why doesn't CSS connect to Django?
Good day, the second day I can not figure it out. The organization of the project is as follows:
mysite ---
\ static ---
| my_css.css
\ templates ---
|base.html
STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join(BASE_DIR, "mysite","media")
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(BASE_DIR, "mysite", "static")
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{% block title %} {% endblock %}</title>
<link rel="stylesheet" href="{{ STATIC_URL }}my_css.css">
</head>
<body>
<h1>My site current time</h1>
{% block content %} {% endblock content %}
{% block footer %}
<hr>
<p>Thank you for your come.</p>
{% endblock %}
</body>
</html>
h1 {
font-size: 120%;
font-family: Verdana, Arial, Helvetica, sans-serif;
color: red;
}
Answer the question
In order to leave comments, you need to log in
for example, the code from settings.py, below in the picture is the directory structure and its location relative to the project root. put scripts and stuff in static_files
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static', 'static_root')
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static', 'static_files'),
)
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'static', 'media')
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Well first compare
STATIC_URL = '/static/'
and
GET /time/static/my_css.css
Secondly, deal with STATIC_ROOT and STATICFILES_DIRS
Well, read
the docs https://docs.djangoproject.com/en/1.8/howto/static...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question