if settings.DEBUG:
urlpatterns += patterns('',
(r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': '/path/to/media'}),
)welcome aboard!
> I have two problems, and I think they are related.
They are indeed
> to documentation on how to get the web server to "serve" the
> images. I hate to put it this bluntly, but I don't know what
> that means
To "serve" simply means that the web-server (usually Apache or
lighttpd) listens for requests for files and responds by
"serving" them. An example might be
C: GET /blog/2008/3/14/my-pi-day-post HTTP/1.1
C: Host: www.example.com
S: HTTP/1.1 200 OK
S: Date: Mon, 23 May 2005 22:38:34 GMT
S: Server: Apache/1.3.3.7 (Unix) (Red-Hat/Linux)
S: Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT
S: Etag: "3f80f-1b6-3e1cb03b"
S: Accept-Ranges: bytes
S: Content-Length: 438
S: Connection: close
S: Content-Type: text/html; charset=UTF-8
S:
S: <html><body>My first blog page</body></html>
(C = client/webbrowser, S = server).
It may be helpful to learn some rudimentary HTTP (the protocol
over which all of this is being served).
http://en.wikipedia.org/wiki/HTTP
Or at least install the "Live HTTP Headers" FireFox extension
that allows you to watch/record the HTTP transactions. But the
basic gist is that your browser requests a page; the server
"serves" this page (dynamically, created by via Django). Your
browser then sees references to other external files (images,
CSS, JavaScript, etc) and makes requests for each of these. The
server receives each request and returns ("serves") the requested
content--an image, a CSS file, a JavaScript file, or even
additional dynamic content from another Django source.
> I would like to know how to "do" images locally, then what I
> need to do when I host my site.
>
> The other problem is getting css to work with my site.
Both images and CSS files (as well as JavaScript source files,
when you get there) are considered "static media".
Django's development server can serve these static media files.
I like to use the following in my urls.py file:
if 'runserver' in argv:
urlpatterns += patterns('',
(r'^media/(?P<path>.*)$',
'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT}
),
)
This allows me to serve media from the development server (which
get put in the directory specified by MEDIA_ROOT), but it
doesn't alter my urlpatterns in production where the actual
web-server handles serving media. To move to production, you'll
want to configure your server (likely Apache or lighttpd) to
serve these static files. The server is very good at serving
static (non-dynamic content), so it's best to let it handle these
files. Django *can* handle them, but it's not designed to do as
much (it's designed to serve dynamic content). There's a good
writeup at
http://www.djangoproject.com/documentation/static_files/
regarding how to configure your web-server (Apache or lighttpd)
for serving these static files outside of Django.
Hopefully this gives you some hints, pointers in the right
direction, terminology to search the web, and tips in general to
get things working. As always, the list is a pretty friendly
place, and will try and help guide you.
-tim
I have followed Doug Van Horn's detailed explanation very closely. I
have also read the Django documentation page on this particular
topic. But for some reason, I still cannot get the thing to work.
Here is my situation: In my <full path>/Programming/Python/Django
directory I have created a project called TestProject, and in
TestProject I have an app called TestApp.
Also in TestProject I have Media/JavaScript/MyJSFile.js. In urls.py I
have the following line:
(r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': '<full path>Programming/Python/Django/TestProject/
Media'}),
I have also specified '<full path>/Programming/Python/Django/
TestProject/Media' as my MEDIA_ROOT and '/media/' as MEDIA_URL in
settings.py. I have read the documentation very carefully, and I
believe I am doing everything correctly.
I have <script type="text/javascript" src="media/JavaScript/