Natalia Osysko
Natalia Osysko

Reputation: 37

Static files django

I'm starting learn Django and I stop on one thing - static files. I tried like its below make changes in seetings and html but it doesnt load on the website. Please help me !

**settings.py:**

STATIC_ROOT = '/PycharmProjects/django_kurs/filmyweb/static/'

STATIC_URL = '/static/'

STATICFILES_DIRS = ['django_kurs/filmyweb/static/',]

**filmy.html:**

{% load static %}
<!doctype html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <title>Document</title>
    <link rel="stylesheet" href="{% static 'moj.css' %}">
</head>


Thank You in advance !

Upvotes: 1

Views: 79

Answers (1)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 477804

The changes to the settings is not sufficient, you need to add the handler for static files to the urls.py:

# urls.py

from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    # …
]

urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Here we thus add views for the static and the media files (last line).

Note that Django does not serve static/media files on production. On production you typically configure nginx/apache/… to do this.

Upvotes: 1

Related Questions