404 error imageI have tested my app in development and successfully got it fully functional in development running on my local server. I have now been trying to push it into development and none of the static files are being served. The connection has been successful as the domain shows the app with just plain HTML. However, all static files are returning the same 404 error.
i have tried to modify my static_root in my settings.py. I have my paths set up like this:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_URL = "static/" STATIC_ROOT = os.path.join(BASE_DIR, 'static')
CodePudding user response:
try this :
urls.py
from django.conf.urls.static import static
urlpatterns = [
...
...
] static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) \
static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
settings.py
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
Or just try this command:
python manage.py collectstatic
CodePudding user response:
try this on top every HTML file if you didn't:
{% load static %}
this is because when you add some static files then you must tell manually the template to load those static file.
for more you can see here