【问题标题】:css files in django hosted on webfactiondjango 中的 css 文件托管在 webfaction 上
【发布时间】:2023-04-04 16:25:01
【问题描述】:

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

谢谢!

【问题讨论】:

    标签: python django webfaction


    【解决方案1】:

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

    <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: how do you serve media / stylesheets and link to them within templates

    【讨论】:

    • 感谢您的回复。所以在这个例子中,在我的 settings.py 文件中我会有 STATIC_URL = '/home/shop/webapps/django/shop' 对吗?我不确定为什么它不起作用。
    【解决方案2】:

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

    您需要将它放在一个媒体文件夹中并以某种方式指向它。 Django deployment via modwsgi 我就是这样做的。

    编辑

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

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

    /home/username/webapps/django_application/media/
    

    对于标准媒体/静态文件

    【讨论】:

    • 感谢您的回复,链接真的很有帮助:)
    猜你喜欢
    • 2014-04-12
    • 2018-06-05
    • 2010-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-01
    • 2015-07-08
    相关资源
    最近更新 更多