[英]Configuring Django static folder for python anywhere
I am new in Django, previously I had a test site in which my static files were placed in static folders. 我是Django的新手,之前我有一个测试站点,在该站点中,我的静态文件位于静态文件夹中。 There was a static folder for every app.
每个应用都有一个静态文件夹。 But now I want to make a site, which will be deployed to python anywhere and so I have to have only one static folder.
但是现在我想创建一个站点,该站点将部署到任何地方的python,因此我只需要一个静态文件夹。
This is the project folder: https://github.com/martin-varbanov96/fmi-fall-2016/tree/master/django/click_bait/miranda 这是项目文件夹: https : //github.com/martin-varbanov96/fmi-fall-2016/tree/master/django/click_bait/miranda
You can see that in the settings file I have: 您可以在我的设置文件中看到:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static")
in my target html file I have 在我的目标html文件中
<link rel="stylesheet" href="{% static 'home/css/style.css' %}" type="text/css">
which returns 404. 返回404。
What is wrong how should I arrage my folders so that they are best working for the pythonanywhere host? 有什么问题我该如何对我的文件夹进行配置,以使其最适合pythonanywhere主机?
If you're getting a 404 error you should ensure debugging mode is on. 如果出现404错误,则应确保打开调试模式。 If I assume it is on (as it is in the
settings.py
you have on GitHub), then your web server just isn't serving the static files. 如果我假设它处于启用状态(就像在GitHub上的
settings.py
),则您的Web服务器只是不提供静态文件。 I would ensure you've run python manage.py collectstatic
which will push the static files for the project to the static folder you've defined in settings.py
. 我将确保您已运行
python manage.py collectstatic
,它将把项目的静态文件推送到您在settings.py
定义的静态文件夹中。
I would also ensure that you've configured Python Anywhere to serve these files. 我还将确保您已配置Python Anywhere来提供这些文件。 According to their website (source: https://help.pythonanywhere.com/pages/DjangoStaticFiles/ ) you should ensure you have that static folder added so their server knows to serve the files.
根据他们的网站(来源: https : //help.pythonanywhere.com/pages/DjangoStaticFiles/ ),您应该确保已添加了静态文件夹,以便他们的服务器知道要提供文件。 The steps at that link are as follows:
该链接上的步骤如下:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.