Search code examples
pythondjangowebfaction

css files in django hosted on 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!


Solution

  • Why are you referencing this stylesheet absolutely?

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

    Just refer to the static directory, as it takes care of static file loading for you:

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

    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