Unable to load JavaScript and images in Django

Could not able to load any javascript files and images Source in Browser instead of using global... also tried to use app level static but nothing changes

setting.py and directory




Create a folder called assets and put the static files in it

And put these settings of static and media files in the settings.py file and comment the previous settings :

STATIC_URL = 'static/'

    BASE_DIR / "assets",
MEDIA_URL = 'media/'
MEDIA_ROOT = 'media/'

Put this piece of code in the urls.py file :

from django.conf.urls.static import static
from django.conf import settings

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

urlpatterns += urlpatterns + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

In your Terminal, it looks like it is able to successfully get to most of the static files we can see (code 200), and there are only a few unavailable resources (code 404). We can't really see anything about errors loading js and image files in your screenshot of the Source in Browser.

If some files are available and some new ones are not, one possibility is you may need to run django's 'collectstatic' command, to collect all static files into the folder where they will be served from - like: python manage.py collectstatic https://docs.djangoproject.com/en/4.1/ref/contrib/staticfiles/#collectstatic

Back to Top