webfaction 上托管的 django 中的 css 文件
我正在 webfaction 上运行 django,但在实现我的 css 文件时遇到问题。我拥有的示例 html 文件是:
<html>
<head>
</head>
<h1>
Poll
</h1>
<body>
<link rel="stylesheet" type="text/css" href="/home/shop/webapps/django/shop/static/index.css" />
<form name="Search bar" action="/search/results/p=1/" method="post">
{% csrf_token %}
UserId: <input type="text" name="UserId" /><br><br>
<input type="text" name="Keyword" />
<input type="submit" value="Search" />
</form>
</body>
</html>
完全相同的文件在我的本地服务器上运行良好,但在 webfaction 上不起作用。我想知道是否有人知道出了什么问题。
谢谢!
I'm running django on webfaction, and am having trouble implementing my css files. A sample html file I have is:
<html>
<head>
</head>
<h1>
Poll
</h1>
<body>
<link rel="stylesheet" type="text/css" href="/home/shop/webapps/django/shop/static/index.css" />
<form name="Search bar" action="/search/results/p=1/" method="post">
{% csrf_token %}
UserId: <input type="text" name="UserId" /><br><br>
<input type="text" name="Keyword" />
<input type="submit" value="Search" />
</form>
</body>
</html>
The exact same file runs fine on my local server, but doesn't work on webfaction. I was wondering if anyone has an idea of whats going wrong.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您为什么绝对引用这个样式表?
只需参考
static
目录,因为它会为您处理静态文件加载:如果您想了解如何设置媒体文件夹,请查看此处:Django:如何提供媒体/样式表并在模板中链接到它们
Why are you referencing this stylesheet absolutely?
Just refer to the
static
directory, as it takes care of static file loading for you:If you'd like to know how to set up your media folder, look here: Django: how do you serve media / stylesheets and link to them within templates
您无法引用本地文件。
/home/shop/webapps/django/shop/static/index.css
是您的硬盘位置。您需要将其放入媒体文件夹中并以某种方式指向它。
通过 modwsgi 部署 Django 是我的做法。
编辑
对webfaction的快速搜索让我得到了:http://docs.webfaction.com/software/django/getting-started.html#serving-static-media
如果您将其放入应用程序文件夹中的媒体文件夹中,则需要类似以下内容
:标准媒体/静态文件
You can't reference a local file.
/home/shop/webapps/django/shop/static/index.css
is your hard drive location.You need to put it in a media folder and point to it some how.
Django deployment via modwsgi is how i do it.
EDIT
a quick search on webfaction got me: http://docs.webfaction.com/software/django/getting-started.html#serving-static-media
if you put it in a media folder in your application folder you need something like:
For standard media/static files