0

I have followed the doc for Managing static files in django 1.5.8

Make sure that django.contrib.staticfiles is included in your INSTALLED_APPS.

Done, and 'django.contrib.staticfiles.finders.AppDirectoriesFinder' is in my STATICFILES_FINDERS

In your settings file, define STATIC_URL, for example:

STATIC_URL = '/static/'

Done

My HTML (for test) :

{% load staticfiles %}
"{% static 'selfcareapi/header_selfcare_api.png' %}"

Then

Store your static files in a folder called static in your app. For example my_app/static/my_app/myimage.jpg.

Here is my file organisation :

Project
|
|-selfcareapi
|    |
|    |-views.py
|    |-static
|        |
|        |-selfcareapi
|            |
|            |-header_selfcare_api.png
|-templates
    |
    |-selfcareapi
        |
        |-my_html.html

The rendered html give me

/static/selfcareapi/header_selfcare_api.png

Which seems OK.

When I runserver and go to : localhost/static/selfcareapi/header_selfcare_api.png, I have a 404 error...

Why does not runserver serve the static files ?

Community
  • 1
  • 1
Laurent
  • 1,710
  • 4
  • 25
  • 46

1 Answers1

1

Are you serving from runserver?

If so, did you add this to you urls.py?

urlpatterns += staticfiles_urlpatterns()

Also make sure your app is in INSTALLED_APPS in settings.py

twined
  • 430
  • 3
  • 7
  • Team issue here ^^ Whe are 5 to works on this project and the guy who did the app forgot to add it in INSTALLED_APPS and I forgot to check it.... Thanks twined ! – Laurent Oct 02 '14 at 09:23
  • What is the use of urlpatterns += staticfiles_urlpatterns() ? It works for me without that ! – Laurent Oct 02 '14 at 09:24