After reading more about common Django project structure, I renamed my 'media' folder to 'static' since it contains the CSS, javascript, and images for my web app and no user uploaded files. However, my project isn't finding the new directory, and the favicon is still being served and can be downloaded from the old directory at localhost:8000/media/images/favicon.png!
In my template, I am linking directly to css/js files like so:
<link href="/static/css/map.css" type="text/css" rel="stylesheet" />
There's also nothing interesting going on in urls.py:
urlpatterns = patterns('',
url(r'^$', 'EventMapperApp.views.map', name='map'),
# AJAX
url(r'^all_events/', 'EventMapperApp.views.all_events'),
url(r'^user_created_events/', 'EventMapperApp.views.user_created_events'),
url(r'^all_user_events/', 'EventMapperApp.views.all_user_events'),
# event actions
url(r'^save_event/', 'EventMapperApp.views.save_event'),
url(r'^unsave_event/', 'EventMapperApp.views.unsave_event'),
)
Any ideas?
For some reason, I thought that urls.py didn't have to resolve all URLs for my Django app? Not really sure what I was thinking... Anyway, I've made what I thought were the appropriate changes to my code as per the documentation, but I'm still having some trouble getting it working.
settings.py
PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/var/www/example.com/media/"
MEDIA_ROOT = (os.path.join(PROJECT_PATH, "media"))
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://example.com/media/", "http://media.example.com/"
MEDIA_URL = '/media/'
# 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/"
STATIC_ROOT = (os.path.join(PROJECT_PATH, "static"))
# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = '/static/'
urls.py
urlpatterns = patterns('',
# Examples:
url(r'^$', 'EventMapperApp.views.map', name='map'),
# Required to make static serving work
(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),
# AJAX
url(r'^all_events/', 'EventMapperApp.views.all_events'),
url(r'^user_created_events/', 'EventMapperApp.views.user_created_events'),
url(r'^all_user_events/', 'EventMapperApp.views.all_user_events'),
# event actions
url(r'^save_event/', 'EventMapperApp.views.save_event'),
url(r'^unsave_event/', 'EventMapperApp.views.unsave_event'),
)
template
<link rel="icon"
type="image/png"
href="{{ STATIC_URL }}images/WWWfavicon.png" />
<link href="{{ STATIC_URL }}css/map.css" type="text/css" rel="stylesheet" />
<link href="{{ STATIC_URL }}css/ui-lightness/jquery-ui-1.8.21.custom.css" type="text/css" rel="stylesheet" />
<link href="{{ STATIC_URL }}css/timepicker.css" type="text/css" rel="stylesheet" />
I'm not sure what I'm doing wrong now... STATIC_ROOT
seems to be resolving properly when I walk through the code (the 'static' folder is in the same directory as settings.py).
As per https://docs.djangoproject.com/en/dev/howto/static-files/#serving-static-files-in-development, I changed urls.py to the following:
from django.conf.urls import patterns, url
from django.conf import settings
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns = patterns('',
# Examples:
url(r'^$', 'EventMapperApp.views.map', name='map'),
# AJAX
url(r'^all_events/', 'EventMapperApp.views.all_events'),
url(r'^user_created_events/', 'EventMapperApp.views.user_created_events'),
url(r'^all_user_events/', 'EventMapperApp.views.all_user_events'),
# event actions
url(r'^save_event/', 'EventMapperApp.views.save_event'),
url(r'^unsave_event/', 'EventMapperApp.views.unsave_event'),
)
# only in development
urlpatterns += staticfiles_urlpatterns()
Still no luck.