Forums

With staticfiles_urlpatterns: "Empty static prefix not permitted"

I am very new to Python and Django, and I am sorry if this is a really stupid question. I couldn't find a solution in the forum or Google.

I followed the tutorial on: http://tutorial.pythonanywhere.com/django

Everything went fine until I modified urls.py. Enabling the two lines

20 from django.contrib.staticfiles.urls import staticfiles_urlpattern
21 urlpatterns += staticfiles_urlpatterns()

gives me an Exception: ImproperlyConfigured, Empty static prefix not permitted

Disabling the two lines things work, but I dont get the admin css.

This is how my urls.py looks like:

1 from django.conf.urls.defaults import patterns, include, url
2
3 # Uncomment the next two lines to enable the admin:
4 from django.contrib import admin
5 admin.autodiscover()
6
7 urlpatterns = patterns('',
8 # Examples:
9 # url(r'^$', 'HIT.views.home', name='home'),
10 # url(r'^HIT/', include('HIT.foo.urls')),
11
12 # Uncomment the admin/doc line below to enable admin documentation:
13 # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
14
15 # Uncomment the next line to enable the admin:
16 url(r'^admin/', include(admin.site.urls)),
17 )
18
19 # Uncomment these two lines to enable your static files on PythonAnywhere
20 from django.contrib.staticfiles.urls import staticfiles_urlpatterns
21 urlpatterns += staticfiles_urlpatterns()

What am I doing wrong?

What does your settings.py looks like? Do you have DEBUG enabled?

DEBUG is enabled.

The following are the lines I changed in settings.py

DATABASES = {

'default': {

    'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.

    'NAME': '******',                      # Or path to database file if using sqlite3.

    'USER': '******',                      # Not used with sqlite3.

    'PASSWORD': '********',                  # Not used with sqlite3.

    'HOST': 'mysql.server',                      # Set to empty string for localhost. Not used with sqlite3.

    'PORT': '',                      # Set to empty string for default. Not used with sqlite3.

}

}

INSTALLED_APPS = (

'django.contrib.auth',

'django.contrib.contenttypes',

'django.contrib.sessions',

'django.contrib.sites',

'django.contrib.messages',

'django.contrib.admin',

'HIT.diet'

)

Hi again,

I just found the problem. I actually had copied the settings.py file from a different project, and the STATIC_* variables were missing.

Stupid me. Sorry for bothering you!

Great, everything works like a charm! :) Have a nice weekend and a happy new year!

Excellent. Glad you got it working.