tags:

views:

28

answers:

2

So I have been looking up and down for a good solution to display images, audio, media in general with django:

From what I found there is the following solutions:

1. Photologue:

Cant seem to make it work. It needs PIL and libjepg.

I tried to install both, but ran into different build problems.

Someone on stackoverflow recommended me this link:

http://appelfreelance.com/2010/06/libjpeg-pil-snow-leopard-python2-6-_jpeg_resync_to_restart/

Which is a great tutorial and also deals with removing PIL and reinstalling (which I have to do, I guess). But somewhere along this tutorial I have to do this:

sudo rm -Rf build

And I dont feel confident enough to run a sudo rm command.

Also I thought there must be an easier way to achieve this, since EVERY Blog needs to display media.

2. Django itself says:

Let Apache do the display and use this:

(r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
        {'document_root': '/pathtomedia/', 'show_indexes': True}),

for development BUT not for production.

So what does everybody use for production?

3. Other:

I managed to display images via os.listdir , urllist and a template:

allimg= os.listdir("/pathtomyimages/")
 urllist = ['/site_media/Imagedir/%s' % url for url in allimg]
 return render_to_response('picture_display.html',
       {'allimg': allimg})

But this also seems not very promising, since I want to display images, audio, media from one directory on multiple sites.

I hear paginator could be the solution.

So now my question:

What is the best, easiest and robust solution to display media in django in development and in production?

What are you using?

Please help me out!

Thanks for the time.

A: 

django-photologue is an app for managing images and image collections for your project but isn't directly related to serving static media.

Since "best", "easiest", and "robust" are all fairly subjective terms depending on your specific needs, I recommend you first seek to understand why it is not common practice to serve your media files from Django. The short, generic answer is that Django must be loaded into each web server process that handles a request and this will use a non-trivial amount of memory. When serving a media file you (usually) just return a file from disk. Since no application logic is required you are incurring unnecessary overhead both from the memory required to run Django in a process and the extra code processing that will occur for Django to map the request path back to a view, load the file, and dump it into the response. Web servers (Apache, Nginx, etc.) are already very good at returning files from disk. This is why it is recommended that you have your web server handle static media files. The request does not ever need to get handed off to the WSGI middleware or Django.

There are many options available but there are a few that are likely to be common solutions. For example, if you've decided on Apache as your web server, you would need to configure it so that requests to your media path are handled directly by Apache and all other requests are handed off to Django. Apache + mod_wsgi is a fairly common choice AFAICT. Read through this carefully:

http://docs.djangoproject.com/en/1.2/howto/deployment/modwsgi/#howto-deployment-modwsgi

It is not strictly necessary to configure a separate web server as the documents recommend. You can use the same Apache instance for Django and media as you're getting started.

Brian Luft
Very interesting! Thanks a lot for this answer. So I have to refine my question:1. Is there a good app for managing static files you know of.2. So the structure of the site with media_url and media_root remains untouched? I can develop my project and when I deploy I just have to configure apache with mod_wsgi and my site will work excellent?Thanks again
MacPython
A: 

Hi. That tutorial is actually mine :)

the sudo RM -rf build, all this does is actually force remove any previous builds, which basically means it clears anything to do with the builds.

hope this helps

ApPeL