Skip to content

Commit

Permalink
refactoring serving of media files in development environment
Browse files Browse the repository at this point in the history
  • Loading branch information
hypertexthero committed Apr 7, 2011
1 parent 6805ec1 commit 26e7d26
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
7 changes: 7 additions & 0 deletions media/css/mysite.css
@@ -0,0 +1,7 @@
/* mysite.css stylesheet */

/*
If blue border appears on top of page, static media is working:
- http://docs.djangoproject.com/en/1.3/howto/static-files/
*/
body {border-top:5px #6CF solid;}
Binary file added media/favicon.ico
Binary file not shown.
4 changes: 2 additions & 2 deletions settings-example.py
Expand Up @@ -60,7 +60,7 @@

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
STATIC_URL = ''

# URL prefix for admin static files -- CSS, JavaScript and images.
# Make sure to use a trailing slash.
Expand All @@ -72,7 +72,7 @@
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
'/full/path/to/mysite/myproject/static'
''
)

# List of finder classes that know how to find static files in
Expand Down
4 changes: 2 additions & 2 deletions templates/base.html
Expand Up @@ -12,8 +12,8 @@
.quiet {color:#999;}
</style>

<link rel="stylesheet" href="{{ STATIC_URL }}css/mysite.css" type="text/css" media="screen" title="default" charset="utf-8" />
<link rel="Shortcut Icon" href="{{ STATIC_URL }}favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="{{ MEDIA_URL }}css/mysite.css" type="text/css" media="screen" title="default" charset="utf-8" />
<link rel="Shortcut Icon" href="{{ MEDIA_URL }}favicon.ico" type="image/x-icon" />

</head>
<body>
Expand Down
14 changes: 8 additions & 6 deletions urls.py
@@ -1,9 +1,5 @@
from django.conf.urls.defaults import patterns, include, url

# Importing staticfiles_urlpatterns
# - http://docs.djangoproject.com/en/1.3/howto/static-files/#staticfiles-development
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
Expand All @@ -23,5 +19,11 @@
# (r'^foo/(?P<id>\d+)/$', 'direct_to_template', {'template': 'foo_detail.html'}),
)

# Importing staticfiles_urlpatterns
urlpatterns += staticfiles_urlpatterns()
# Serving static/media files could be better with Django. Here's how to do it in the development server (and use href="{{ MEDIA_URL }}css/mysite.css" in mysite/myproject/templates/base.html). In production I believe it will be controlled by a setting in mysite/myproject/etc/nginx.conf
# http://docs.djangoproject.com/en/dev/howto/static-files/#serving-static-files-in-development
from django.conf import settings

if settings.DEBUG :
urlpatterns += patterns('',
url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
)

0 comments on commit 26e7d26

Please sign in to comment.