I'm trying to find a way, how to tell the Django
where static
files like css
are stored. The problem is that it can't find the static
folder probably. I've set the settings.py
file already but it did not help.
SETTINGS.PY:
STATIC_URL = '/static/'
INSTALLED_APPS = (
...
'django.contrib.staticfiles',
)
BASE.HTML:
...
...
<title>Rozcestník</title>
<!-- Bootstrap core CSS -->
{% load static %}
<link href="{% static "css/bootstrap.min.css" %}" rel="stylesheet">
...
PROJECT STRUCTURE:
Where is the problem?
I don't like much you directory (structure).
If the folder "web" is an app and "dedo" is a folder with settings, than you cannot have folders "static" and "templates" inside your app folder.
It shoud be:
dedo
__init__.py
settings.py
urls.py
views.py
static
css
bootstrap.min.css
templates
base.html
index.html
web
migrations
__init__.py
admin.py
models.py
tests.py
views.py
db.sqlite3
manage.py
And in your setttings.py you need to write this:
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATIC_URL = access via browser to your static files
STATICFILES_DIRS = where Django will look up static files
IMPORTANT:
STATIC_ROOT = is used ONLY if you are going to deploy your web app via appropriate web server (nginx, apache, ...) with WSGI (gunicorn, modwsgi, ...)
"python manage.py collectstatic" or "python3.X manage.py collectstatic" are commands for copying your static files from STATICFILES_DIRS (plus static files for /admin/) to STATIC_ROOT, which means that STATIC_ROOT mustn't be the same as STATICFILES_DIRS.
I guess you didn't use the "Collect static" action.
In your shell/CMD run:
python manage.py collectstatic
If it didn't solve your problem post the error you're getting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With