Changing django default static directory
I'm having a problem with Django 1.6:
I want to change the default static file directory in django. I do not want this in
project/myapp/static
, but inproject/static
I have read the django documentation, added
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR,'static')
STATICFILES_DIR =(os.path.join(BASE_DIR, 'static'),)
In my settings.py
Then I ran ./manage.py collectstatic
and the files copied as expected.
Finally I started the server, the application uses the django plugin for templates, so my template starts with:
{% extends 'dh5bp/base.html' %}
{% load url from future %}
{% load staticfiles %}
{% block head %}
<link rel="stylesheet" href="{% static "css/homepage.css" %}">
{% endblock %}
And the Css is not loading: but in my server log I got this:
[29/Aug/2014 11:23:03] "GET /static/js/dh5bp/plugins.js HTTP/1.1" 304 0
[29/Aug/2014 11:23:03] "GET /static/css/homepage.css HTTP/1.1" 404 1657
As you can see, the statics file from dh5bp (boiler stove plugin) loaded correctly, and the statics from my application loaded incorrectly.
I tried adding + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
to my urls.py, right after urlpatterns, it didn't work.
So if someone can tell me to chat, I'm doing badly and what should I change in the settings. This could be great
EDIT:
Tried the solution here , it gives me the same result: only the statics from the template are loaded.
And not to mention that I was obviously checking if the files in / project / static exist, they exist.
EDIT 2:
I tried to put the old folder in my application to make sure it doesn't look for files in the old folder. It's not, so I don't know where django expects this file to be? Is there a debugging method that can help with this?
source to share
Yours STATIC_ROOT
shouldn't be in STATICFILES_DIRS
. STATICFILES_DIRS
should contain paths to static files of the project. STATIC_ROOT
is where all your static files are collected at startup collectstatic
.
If you start the django server with DEBUG = True, the server will serve static files with a straight form STATICFILES_DIRS
, and if DEBUG = False, it will not serve static files at all. In this case, you can start the django server with the option --insecure
.
source to share