views:

39

answers:

4

I have a couple of conceptual questions:

  1. regarding serving static files (media) in Django in production.

I understand that Django serves static files in development different than in production:

read this:

http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#serving-media-files http://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/#howto-deployment-modwsgi

Which one is the way to go? mod python or mod wsgi?

What would be a excellent file structure to store all the files of a django website,: e.g. js, python code, media etc when using either of the two options above?

  1. Another conceptual difficulty I have is regarding templates:

If I have a template and in that template I have variables like {{ variable.name }} or tags {% tagname %} and I want to write in this variable or tag either text, images, sounds, videos etc, how does the def in the view.py (where I believe it has to be stored to be then written in the template) be written to "write" into the template.

I hope that is not confusing and to complicated. What I dont understand is the process how I can write into a template.

I know it takes variables, these are defined in the view, but I dont understand what steps conceptually I need to write to this template.

Thanks!

A: 

mod_python is dead. Use mod_wsgi. Put nothing under the document root. Put the Alias directives for your static media before the WSGIScriptAlias directive.

The context variables are passed to the render function as appropriate.

Ignacio Vazquez-Abrams
The ordering of Alias and WSGIScriptAlias doesn't matter. Alias directives always take precedence over WSGIScriptAlias.
Graham Dumpleton
Thanks! Will do that for the first question. Second question: I read the django tutorial on the render template. I understand the text part perfectly fine, what I dont understand is how it renders static files like images, sounds. Or in other words how do I serve an image to this template variable? In View write a def that defines the Variable = <img source = /mymediapath/>?
MacPython
+1  A: 

The choice of mod_python vs mod_wsgi has absolutely nothing to do with serving static files. On the contrary, the whole idea is that you use the standard Apache serving functionality for that, and mod_python/wsgi runs the Python code for your Django app. That said, you should definitely use mod_wsgi - mod_python is now abandoned and unsupported.

I don't think I really understand the second part of your question. If I'm reading it correctly, you're asking how the template knows how to serve the assets. Well, it doesn't. You just pass the URL path to those assets, which is usually based on the MEDIA_URL setting.

Daniel Roseman
Thanks! ad 1: So Mod_wsgi it is. ad 2: Ok. And when I go to production I will serve the "assets" through apache and have to change my code massively?
MacPython
Why should you need to change your code? It's just a single URL, which is set in settings.py. You just need to change that.
Daniel Roseman
Ok, great thanks!
MacPython
A: 

Apropos your first question, According to Graham Dumpleton (the author of mod_wsgi), mod_python is officially dead so for a new project, it's best to stick to mod_wsgi.

Noufal Ibrahim
A: 

Regarding your comment about having to change many things between development and production:

There's a good page here that gives good tips on setting up your development environment vs production for serving static pages. If you set things up correctly, you'll have very little to change vs. development and production... in fact, in this example, you'll simply change your DEBUG setting in settings.py to True for development and False in production.

Beyond that, if you research the use of a local_settings.py that you exclude from your source control, then you'll have nothing to change vs. dev and production since your development settings will be in local_settings.py -- but that's a whole other topic. :-)

Tony Guinta
Very helpful. Thanks! It is very advanced, I have to understand it. Thanks for mentioning.
MacPython