Django找不到我的静态文件 [英] Django cannot find my static files
问题描述
对于Web开发人员,我还比较陌生.并且我正在尝试构建我的第一个Web应用程序.我在project_root/static中有我的静态文件夹,但是由于某些原因,我在运行服务器时不断收到404:
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:
:/users/login/js/bootstrap.min.js例如.
Not Found: /users/login/js/bootstrap.min.js for example.
我的html顶部和settings.py中有{%load staticfiles%},我有:
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')
谢谢.
已通过以下答案的组合进行修复.谢谢大家!
Fixed with a combination of the answers below. Thank you all!
推荐答案
继续阅读以下内容- http://agiliq.com/blog/2013/03/serving-static-files-in-django/
摘要:如果"users"是项目中的应用程序名称,然后创建目录-'users/static/js/'.并将bootstrap.min.js放入js/.可以在localhost:8000/static/js/bootstrap.min.js上访问此文件.继续尝试一下.
Summary: If "users" is the app name in your project, then create directory - 'users/static/js/'. and put bootstrap.min.js into js/. This file will be accessible at localhost:8000/static/js/bootstrap.min.js. Go ahead and try it out.
这篇关于Django找不到我的静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!