0

I am having an issue with my website getting the static files to render for the website and i don't know what the issue might be.

I noticed that the static files are working for only the home page and I have a response like this from the terminal.

They all share common base files which they use to render.

homepage response on the terminal

[06/Mar/2021 17:58:34] "GET / HTTP/1.1" 200 19153
[06/Mar/2021 17:58:34] "GET /static/img/logo/logo-new.png HTTP/1.1" 200 9967
[06/Mar/2021 17:58:34] "GET /static/img/icon/icon1.svg HTTP/1.1" 200 5207
[06/Mar/2021 17:58:35] "GET /static/js/vendor/modernizr-3.5.0.min.js HTTP/1.1" 200 8638
[06/Mar/2021 17:58:36] "GET /static/js/popper.min.js HTTP/1.1" 200 19191
[06/Mar/2021 17:58:36] "GET /static/js/vendor/jquery-1.12.4.min.js HTTP/1.1" 200 97166
[06/Mar/2021 17:58:36] "GET /static/js/bootstrap.min.js HTTP/1.1" 200 48950

but for forum page, the response is like this on the terminal

Not Found: /forum/static/js/vendor/jquery-1.12.4.min.js
[06/Mar/2021 17:58:54] "GET /forum/static/js/popper.min.js HTTP/1.1" 404 3627
Not Found: /forum/static/js/select2.min.js
[06/Mar/2021 17:58:54] "GET /forum/static/css/bootstrap.min.css HTTP/1.1" 404 3642
Not Found: /forum/static/js/moment.min.js
[06/Mar/2021 17:58:54] "GET /forum/static/js/vendor/jquery-1.12.4.min.js HTTP/1.1" 404 3669
[06/Mar/2021 17:58:54] "GET /forum/static/js/select2.min.js HTTP/1.1" 404 3630

and like this for about page

[06/Mar/2021 18:02:11] "GET /about/static/img/gallery/about3.png HTTP/1.1" 404 3645
Not Found: /about/static/js/bootstrap.min.js
[06/Mar/2021 18:02:11] "GET /about/static/js/bootstrap.min.js HTTP/1.1" 404 3636
Not Found: /about/static/js/jquery.slicknav.min.js
[06/Mar/2021 18:02:11] "GET /about/static/js/jquery.slicknav.min.js HTTP/1.1" 404 3654
Not Found: /about/static/js/owl.carousel.min.js
[06/Mar/2021 18:02:11] "GET /about/static/js/owl.carousel.min.js HTTP/1.1" 404 3645

settings.py

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "/static/")
#STATICFILES_DIRS = ('assets',)
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'staticfiles')]
#STATIC_ROOT = os.path.join(BASE_DIR, "..", "www", "static")

MEDIA_URL = '/media/'
MEDIA_ROOT = '/media/'

urls.py

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
coderboy
  • 741
  • 2
  • 17
  • Does this answer your question? [django html template can't find static css and js files](https://stackoverflow.com/questions/66437690/django-html-template-cant-find-static-css-and-js-files) – Ivan Starostin Mar 06 '21 at 19:19

1 Answers1

0

I was able to fix the issue. i simply had to change my settings.py file to this:

settings.py

STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]

MEDIA_URL = '/media/'
MEDIA_ROOT = '/media/'
coderboy
  • 741
  • 2
  • 17