开发者

Django Apache static files

开发者 https://www.devze.com 2023-01-07 06:38 出处:网络
I have a couple of conceptual questions: regarding serving static files (media) in Djan开发者_运维知识库go in production.

I have a couple of conceptual questions:

  1. regarding serving static files (media) in Djan开发者_运维知识库go 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!


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.


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.


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.


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. :-)

0

精彩评论

暂无评论...
验证码 换一张
取 消