0

我在 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。我想知道是否有人知道出了什么问题。

谢谢!

4

2 回答 2

3

你为什么要 绝对引用这个样式表?

<link rel="stylesheet" type="text/css" href="/home/shop/webapps/django/shop/static/index.css" />

只需参考static目录,因为它会为您处理静态文件加载:

<link rel="stylesheet" type="text/css" href="/static/index.css" />

如果您想知道如何设置您的媒体文件夹,请看这里:Django:您如何提供媒体/样式表并在模板中链接到它们

于 2011-04-21T04:49:39.870 回答
1

您不能引用本地文件。/home/shop/webapps/django/shop/static/index.css是您的硬盘位置。

您需要将其放在媒体文件夹中并以某种方式指向它。 通过 modwsgi 部署 Django 是我的做法。

编辑

对 webfaction 的快速搜索得到了我:http ://docs.webfaction.com/software/django/getting-started.html#serving-static-media

如果您将其放在应用程序文件夹中的媒体文件夹中,则需要以下内容:

/home/username/webapps/django_application/media/

对于标准媒体/静态文件

于 2011-04-21T04:51:53.893 回答