am trying to load static and adding image in my project and I get this error "GET http://localhost:8000/static/kpn.jpg 404 (Not Found)" please I need your help
1- configure STATIC_URL
on your settings.py
:
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
STATICFILES_DIRS = (
# normpath(join(SITE_ROOT, 'static')),
os.path.join(BASE_DIR, "staticfiles"),
'./staticfiles',
)
2- add STATIC_URL
to your urls.py
:
urlpatterns = [
...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.