I am relatively new to web dev. and I am trying to build my first web application. I have my static folder in project_root/static but for some reason, I keep getting 404s when I run the server:
Not Found: /users/login/js/bootstrap.min.js for example.
I have {% load staticfiles %} at the top of my html and in my settings.py I have:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
Thanks.
EDIT: Fixed with a combination of the answers below. Thank you all!
put your static js, css and other files in a directory called static inside your project directory then these settings will work:
# this defines the url for static files
# eg: base-url.com/static/your-js-file.js
STATIC_URL = '/static/'
# this is directory name where collectstatic files command will put your app level static files
STATIC_ROOT = 'staticfiles'
# this is directory paths where you have to put your project level static files
# you can put multiple folders here
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
based on these settings you will be able to access your static files correctly
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With