[Fixed]-My Django app is not serving static files

0👍

I finally discovered the error: Apache was running as default and serving the html templates in port 80, but without permissions for the static files.

1👍

The settings you have are generally discouraged, for local development they will work fine, however if you were to attempt to run that on a Linux based machine, it wouldn’t work.

Here’s how it should be formatted:

Here are the settings that would make it like that:

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR, 'static', 'static_root')
#this applies to all operating systems
STATICFILES_DIRS = (
 os.path.join(BASE_DIR, 'static', 'static_dirs'),
)

You would put your static folders and files in “static_dirs”, and then whenever you needed to sync to “static_root”. You would type: “python manage.py collectstatic”.

In your template file you would then type:

{% load static from staticfiles %}

<img id="logo" src="{% static "images/logo.png" %}"\>

That should work.

0👍

check if the source is loaded using view source and if yes from there check if any link to your static assets are accessible if present then you have to hard refresh the browser

0👍

Include {% load staticfiles %} in template.

0👍

You comment in reply to the post by Allen Fernandes above indicates you are in DEBUG mode. Is django.contrib.staticfiles in your INSTALLED_APPS?

Leave a comment