[Answer]-Django can't find static files for an app

2👍

✅

Add django.contrib.staticfiles to INSTALLED_APPS in your settings.py.

Remove STATICFILES_FINDERS, STATICFILES_DIRS, STATIC_ROOT from your settings.py.

change your base.html to something like this:

{% load staticfiles %}
<!DOCTYPE html>
<html lang="fa">
    <head>
        <script type="text/javascript" src="{% static 'my_app/js/app.js' %}"></script>
        <title>{{ title }}</title>
    </head>
    <body>
        {% block content %}
        {% endblock %}
    </body>
</html>

0👍

I had faced the same issue which got solved after the following changes.

In HTML pages:

{% load static %}  ## loads the static folder and images inside it. 
<div id='button-holder'><img src="{% static "glass.png" %}" alt="Hi!" /></div> ## for images 
                              src="{% static 'my_app/js/app.js' %} ## for scripts.

In urls.py

urlpatterns = patterns('',...
........
 )+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

After this run command as @Daniel Roseman have mentioned python manage.py collectstatic. The findstatic command can help show you which files are found.
Example

python manage.py findstatic css/base.css admin/js/core.js

You can find help here regarding it.

-1👍

You are supposed to run manage.py collectstatic to copy your app-level static files to the central static directory.

Leave a comment