在Django生产教程上提供静态文件 [英] serving static files on Django production tutorial

查看:86
本文介绍了在Django生产教程上提供静态文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人有关于在Django生产应用程序上提供静态文件的简单分步教程吗?我阅读了Django docs ,听起来确实很复杂...我正在尝试使用lighttpd,nginx或cherokee等不同的服务器来提供静态文件的途径,但是对我来说,设置这些都是希腊文.我下载了lighttpd,尝试按照说明进行安装,并在几秒钟内得到了一个错误.缺少这个或那个或其他...我不是UNIX专家,我也不擅长C/C ++,所以所有这些./configure和MAKE安装对我来说都是乱七八糟的...所以我想我眼前的问题是:

Does anyone have a simple step-by-step tutorial about serving static files on a Django production app? I read the Django docs and it sounds really complicated... I'm trying to go the route of serving static files using a different server like lighttpd, nginx, or cherokee, but setting these up is all Greek to me. I downloaded lighttpd, tried to follow the instructions to install, and within a few seconds got an error. Missing this or that or whatnot... I'm not a UNIX whiz and I'm not very good at C/C++, so all this ./configure and MAKE install are gibberish to me... So I guess my immediate questions are:

  1. 您建议哪个服务器提供易于安装且易于维护的静态文件?
  2. 假设我实际上已启动服务器并开始运行,那又如何呢?如何告诉Django在另一台服务器上查找文件?
  3. 再有没有人有循序渐进的教程?

非常感谢!

推荐答案

对不起,没有逐步教程.但是,这里有一个概述可能会有所帮助:

Sorry, don't have a step by step tutorial. But here is a high level overview that might help:

  1. 您可能希望使用Apache服务器( http://httpd.apache.org/)这是大多数* nix发行版附带的.
  2. 然后您要使用mod python(或如注释者所指出的那样mod_wsgi: http://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/)连接到Django:
  1. You probably want to go with the Apache server ( http://httpd.apache.org/) This comes with most *nix distributions.
  2. You then want to use mod python (or as the commenter pointed out mod_wsgi: http://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/) to connect to Django : http://docs.djangoproject.com/en/dev/howto/deployment/modpython/?from=olddocs. Once you complete this step, Apache is now fronting for Django.
  3. Next you want to collect the static files in your Django into one directory and point apache at that directory. You can do this using the the ./manage.py collectstatic if you used django.contrib.staticfiles (http://docs.djangoproject.com/en/dev/howto/static-files/.)

因此,诀窍是您不告诉Django将提供的静态文件委派给特定的服务器.相反,您是在告诉httpd哪些URL是通过Django提供的,哪些URL是静态文件.

So the trick is you're not telling Django to delegate serving static files to a specific server. Rather you're telling httpd which urls are served via Django and what urls are static files.

另一种说法是,所有请求都到达Apache Web服务器.根据您在httpd.conf中指定的规则,网络服务器将决定请求是针对静态文件还是针对django生成的动态文件.如果它是静态文件,它将仅提供文件.如果请求是针对动态文件的,它将通过modpython将请求传递给Django.

Another way of saying this is that all requests come to the Apache web server. The webserver, according to the rules you specify in httpd.conf, will decide whether the request is for a static file or whether it is for a dynamic file generated by django. If it for a static file it will simply serve the file. If the request is for a dynamic file it will, via modpython, pass the request to Django.

希望有帮助.

这篇关于在Django生产教程上提供静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆