WebFaction
Community site: login faq

I've spent a couple days reading the docs, and am either too tired or too dumb to figure this out. It's a common problem, but I'm just missing something (probably obvious) here.

I have a django project on webfaction that is delivering templates fine. It is not delivering static files, specifically the locally stored css,when settings.DEBUG=False. when DEBUG=True everything works; after toggling to False, I get a 500 error when trying to access http://domain/static/my.css

I'm relatively new, and would appreciate a second pair of eyes on my problem.

###########  Settings.py ###############
import os

#admittedly dirty distinguishment between development workstation
#and webfaction environment, but it seems to work
if os.environ.has_key('HOSTNAME'):
    isdev = False
else:
    isdev = True

if isdev is True:
    DEBUG = True
else:
    DEBUG = False
TEMPLATE_DEBUG = DEBUG

if isdev:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': 'myproject.db',
                    }
                }
else:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': 'myprojectdb',
            'USER': 'username',
            'PASSWORD': 'passwd',
            'HOST': 'webxxx.webfaction.com',
            'PORT': '', 
        }
    }

# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = ['localhost','127.0.0.1',
            'xxx.webfactional.com',
            'code.jquery.com',
                ]  #[edit:]fixed typo: added back in the close bracket

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
if isdev:
    STATIC_ROOT = '/home/username/Dropbox/programming/dev/myproject/static/'
else:
    STATIC_ROOT = '/home/gsekn/webapps/myprojectstatic/'

# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = 'http://gsekn.webfactional.com/static/'

# Additional locations of static files
STATICFILES_DIRS = (
    #no other directories beyond STATIC_ROOT
    )

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

ADMIN_MEDIA_PREFIX = '/static/admin/'

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'debug_toolbar.middleware.DebugToolbarMiddleware',
)

INSTALLED_APPS = (
                'django.contrib.auth',
                'django.contrib.contenttypes',
                'django.contrib.sessions',
                'django.contrib.sites',
                'django.contrib.messages',
                'django.contrib.staticfiles',
                'django.contrib.admin',
                'south',
                'django.contrib.admindocs',
                'debug_toolbar',
                'taggit',
                'myapp',
                )

############### base.html #############
...
<head id="HeadContainer">
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    {% block css_references %}
        {% load staticfiles %}
        <link rel="stylesheet" type="text/css" href="{% static 'myproject_color_palette_jquerymini.css' %}"/>
<!-- note, the above statement produces source code with an active bona fide url to the css, so long as debug = True -->

        <link rel="stylesheet" type="text/css" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile.structure-1.3.2.min.css"/>
        <script  src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
        <script  src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
    {% endblock %} {# end block css_references #}

asked 18 Oct '13, 08:48

gsekn
113
accept rate: 0%

edited 18 Oct '13, 10:44


It could be because you don't have a closing bracket for your ALLOWED_HOSTS

permanent link

answered 18 Oct '13, 10:34

bmeyer71 ♦♦
1.5k3613
accept rate: 33%

Oh, I would have loved for that to be the problem, but unfortunately that is just a typo I introduced in preparing the post. This ] is not missing in my actual settings.py

(18 Oct '13, 10:45) gsekn

i should add that I edited the above post to include the ], thanks for pointing it out.

(18 Oct '13, 11:02) gsekn

I took a quick look at your account. You are currently not serving your static application. Have a look at our docs here. If you still have questions, maybe open a support ticket so we can take a closer look.

(18 Oct '13, 11:07) bmeyer71 ♦♦

... so, my kids are already named, but I'm going to call both of them Bjorn for a few hours in thanks. Rookie mistake, but I appreciate the catch!

(18 Oct '13, 11:33) gsekn

@bmeyer71 in the comment above had the solution.

permanent link

answered 18 Oct '13, 11:33

gsekn
113
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×909
×125
×12
×5

question asked: 18 Oct '13, 08:48

question was seen: 6,000 times

last updated: 18 Oct '13, 11:33

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM