[Django]-Django runserver not serving static files in development

27πŸ‘

βœ…

I managed to fix it.

I created another directory in my project folder called static and copied my static files there.

I then added:

from django.contrib.staticfiles.urls import staticfiles_urlpatterns
import settings
if settings.DEBUG:
    urlpatterns += staticfiles_urlpatterns()

to my urls.py

and

STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)

to my settings.py.

Then, when I deploy I execute manage.py collectstatic and since Apache is configured properly, everything will work!

Based on http://dlo.me/archives/2013/01/14/how-to-serve-static-files-django/

Thanks to all.

πŸ‘€Meir

10πŸ‘

I usually run python manage.py runserver --insecure to force serving of static files with the staticfiles app even if the DEBUG setting is False.

Here’s the link of their documentation. https://docs.djangoproject.com/en/3.2/ref/contrib/staticfiles/#cmdoption-runserver-insecure

πŸ‘€Zeno

Leave a comment