Tim Chase wrote: >> Thanks. Yes, using relative paths is the right idea - it's a shame that >> the base url's have to be hard coded in the templates. I understand >> from a web efficiency standpoint of Django not handling static content >> but from an application development standpoint this is a real complexity >> we don't need. I can see this becoming a real mess when constantly >> updating between development and production. I did see another blog >> which demonstrated a way to use base url variables for static content >> with template tags but again this cummulative complexity for common >> things just becomes a showstopper for us. Somehow the base url path >> should just be a simple entry in Settings.py and defaulted to the >> project location. >> > > > I've gotten around this by adding a couple lines at the bottom of > my urls.py that, if it's running as the development server (as > determined by having "runserver" as an entry in sys.argv), it > adds an entry in the URLs.py to allow Django to handle media: > > # if you want to use the production site's media location > # MEDIA_PATH = settings.MEDIA_ROOT > # if you want to use a different directory for testing purposes > # MEDIA_PATH = '../media' > MEDIA_PATH = '../media' > if 'runserver' in sys.argv: > urlpatterns += patterns('', > (r'^media/(?P<path>.*)$', > 'django.views.static.serve', > {'document_root': MEDIA_PATH} > ), > ) > > It may not be an ideal solution, but it serves my purposes, > allowing me to access my media in development, while still > allowing Apache to handle my media in production. > It seems like a good solution - I still can't get an image displayed - any idea which settings are not matching ? I've tried locating the /media folder in both /myproject and /myapp with no success
template: <img src="/media/sitemap.png"></img> settings.py MEDIA_ROOT = './media/' MEDIA_URL = 'media/' urls.py MEDIA_PATH = '../media' if 'runserver' in sys.argv: urlpatterns += patterns('', (r'^media/(?P<path>.*)$','django.views.static.serve',{'document_root': MEDIA_PATH}), ) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---