Django:静态文件未加载
我的 django 项目包含一个文件夹 STATIC
,其中有它的子文件夹 css
、images
、js
和 >swf
。我的网站无法找到这些文件,从而在终端上运行的开发服务器中引发 404 错误。
我有一个 settings_local.py
文件,其中我设置了路径,例如(在 ubuntu 11.04 上运行)
STATIC_ROOT = '/home/zulaikha/dust.bin/my_project/static/'
STATIC_SERVE_PORT = 80
来自客户端的 sample settings-local.py 文件建议建议如此
# static root
STATIC_ROOT = 'C:/Program Files (x86)/XAMPP/htdocs/static'
STATIC_SERVE_PORT = 8080
我见过一些类似的问题,但都考虑到我读到的 STATICFILES 是在 Django 1.3 中引入的 我哪里错了,我该如何纠正自己?
My django project contains a folder STATIC
in which there are it's child folders css
, images
, js
and swf
. My web-site can not locate these files raising a 404 in the development server running on the terminal.
I have a settings_local.py
file in which I have set the path such as (running on ubuntu 11.04)
STATIC_ROOT = '/home/zulaikha/dust.bin/my_project/static/'
STATIC_SERVE_PORT = 80
The sample settings-local.py file from the client suggest suggest so
# static root
STATIC_ROOT = 'C:/Program Files (x86)/XAMPP/htdocs/static'
STATIC_SERVE_PORT = 8080
I have seen some similar issues but all regard STATICFILES
which I read was introduced in Django 1.3
Where am I wrong and how can I correct myself?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您确实使用 django 1.2,那么您必须安装 django-staticfiles。如果您在客户端包含的 requests.txt 中没有看到它,那么他要么没有将其冻结到文件中,要么没有使用该功能,而只是通过 apache 或其他生产服务器指向它。
请遵循文档中的这些说明。具体来说,基本部分:
https://docs.djangoproject.com/en/dev/howto/static- files/
您需要将静态文件添加到已安装的应用程序中。您也不应该需要手动添加 url,因为 django 应该使用 runserver 命令自动执行此操作。
还要首先通过不使用 sudo 或自定义 IP 和端口运行来验证它是否在本地工作
If you are indeed using django 1.2 then you must install django-staticfiles. If you do not see it in the included requirements.txt from your client then he either did not freeze it out into the file, or was not using that feature and instead was just pointing at it via apache or another production server.
Follow these instructions from the docs. Specifically the basic section:
https://docs.djangoproject.com/en/dev/howto/static-files/
You will need to add staticfiles to your installed app. You should also not need to manually add a url since the django should do it automatically with the runserver command.
Also verify that it works locally first by not running with sudo or a custom ip and port
根据您的评论,这里有两个选择:
According to your comments there are two options here:
以最简单的形式,这就是问题的解决方案。在项目 urls.py 中包含以下几行
)
In the simplest form, this is the solution to the problem. In project urls.py include the following lines
)