4

I got an issue with Django 1.6:

I want to change the default static file directory in django. I don't want it in project/myapp/static but in project/static

I readed django's 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 files copyed as expected.

Finally I launched the server, the app is using django boilerplate plugin, so my template begins 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 won't load: But in my server log, I got that:

[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 see the statics file from dh5bp (Boiler plate plugin) Are loaded correctly, while the statics from my app aren't loaded correctly.

I tried to add + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) to my urls.py, right after urlpatterns, It didn't worked.

So please if someone could tell me chat I'm doing bad and what should I change in the settings. It could be great

EDIT:

Did tryed the solution here, It give me the same result: only statics from boilerplate are loaded.

And not to mention that I've obviously checked if the files exists in /project/static, they does exists.

EDIT 2:

I tried to put the old static folder in my app, to ensure That he weren't looking for the files in the old folder. It doesn't, so I don't know where django expect those file to be? Is there a debug setup that could help on this?

Community
  • 1
  • 1
  • how you set it up base_dir – Raja Simon Aug 29 '14 at 12:02
  • @rajasimon `BASE_DIR = os.path.dirname(os.path.dirname(__file__))`, The default configuration. I'm sure it's the good one as collectstatic did copied in the dir I wanted to. –  Aug 29 '14 at 12:05

1 Answers1

3

Your STATIC_ROOT shouldn't be in STATICFILES_DIRS.
STATICFILES_DIRS should contain paths to your project's static files.
STATIC_ROOT is where all your static files are collected when you run collectstatic.

If you run django server with DEBUG=True, server will serve static files straight form STATICFILES_DIRS, and if DEBUG=False it won't handle static files at all. In that case you can run django server with option --insecure.

See this related question for more.

Community
  • 1
  • 1
draganHR
  • 2,578
  • 2
  • 21
  • 14
  • So according to this, If I change STATICFILES_DIRS To "staticApp", then placing all my app-related static files in it, it should works? –  Aug 29 '14 at 12:49
  • I don't know what "staticApp" is. If you mean "static" directory in your application, then yes, as long as you enable [AppDirectoriesFinder](https://docs.djangoproject.com/en/1.6/ref/settings/#std:setting-STATICFILES_FINDERS) – draganHR Aug 29 '14 at 20:05