It's a bit weird how paths look, but it's my first Django app, I'm learning :)

setting.py

STATIC_ROOT = os.path.join(SITE_ROOT, 'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
    ('assets', 'C:\Users\Szymon\Desktop\UploaderUpdate\Uploader\uploader\static'),
)

urls.py

urlpatterns += staticfiles_urlpatterns()

main.html (template)

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

Then in my cmd I do: python manage.py collectstatic And it says copies files. Now, I have my (I created it) static folder at:

C:\Users\Szymon\Desktop\UploaderUpdate\Uploader\uploader

Unfortunately main app is in folder main so it created folder static at :

C:\Users\Szymon\Desktop\UploaderUpdate\Uploader\uploader\uploader\static

It contains assets and admin. But my CSS is not being used, despite my import in the template. Am I linking it wrong?

有帮助吗?

解决方案 3

I managed to do this - link to the CSS needed to be in {% header %} part of my template.

其他提示

Perhaps try

STATICFILES_DIRS = (os.path.join(SITE_ROOT,'static'))?

I don't know why the absolute path doesn't seem to work. However python manage.py collectstatic should have put all of your static files in the static directory defined by STATIC_ROOT, which uses SITE_ROOT (or BASE_DIR from https://docs.djangoproject.com/en/1.6/howto/static-files/. (I would avoid local absolute paths if you can, for one thing that gives you more work when you go into production.) Also does your SITE_ROOT look like this?

SITE_ROOT = os.path.dirname(os.path.abspath(__file__))

I'm 99% sure this gives the absolute path of the directory your settings.py file is in, so if you use this, your static folder should be in the same directory as your settings file.

Try changing this:

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

by:

<link rel="stylesheet" href="{{ STATIC_URL }}css/style.css">
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top