[英]how to set static files directory in django
I am trying to get an existing django app up and running, but the css or any other static files are not showing up. 我正在尝试启动并运行现有的django应用程序,但是css或任何其他静态文件未显示。 I get the error:
我收到错误:
"GET /static/css/mycss.css HTTP/1.1" 404 50
In the settings the following values are used: 在设置中,使用以下值:
DJANGO_ROOT = dirname(dirname(abspath(__file__)))
SITE_ROOT = dirname(DJANGO_ROOT)
STATIC_ROOT = normpath(join(SITE_ROOT, 'assets'))
STATIC_URL = '/static/'
STATICFILES_DIRS = (
normpath(join(SITE_ROOT, 'static')),
)
The app contains a directory called "static". 该应用程序包含一个名为“静态”的目录。 It is in the current directory structure:
它在当前目录结构中:
my-django-project > my-django-project > static > css > mycss.css
my-django-project> my-django-project>静态> css> mycss.css
When I hit the home url via localhost, I get the above 404 error. 当我通过本地主机访问主URL时,出现上述404错误。
What am I doing wrong? 我究竟做错了什么?
You need to run the collectstatic
command to collect the static files in your apps to the STATIC_ROOT
. 您需要运行
collectstatic
命令将应用程序中的静态文件收集到STATIC_ROOT
。
The command can be run like this: 该命令可以这样运行:
python managy.py collectstatic
More information about static files can be found in the django documentation on static files . 关于静态文件的更多信息可以在静态文件的django文档中找到。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.