Django的一些配置

GreatZhou 2013-06-04

0、Django在线文档

http://py3k.cn/

http://djangobook.py3k.cn/2.0/ 

1、Django开发环境与生产环境的多配置文件设置

  • 设置成两个全面的,彼此独立的配置文件
  • 设置一个基本的配置文件(比如,为了开发)和第二个(为了产品)配置文件,第二个配置文件仅仅从基本的那个配置文件导入配置,并对需要定义的进行复写. 
  • 使用一个单独的配置文件,此配置文件包含一个Python的逻辑判断根据上下文环境改变设置。

 2、Django的日志文件输出

3、Django的多站点协同支持

<VirtualHost *:80>

WSGIDaemonProcess a processes=2 threads=5
WSGIDaemonProcess b processes=2 threads=5

WSGIScriptAlias /a '/path/to/project/a.wsgi'
WSGIScriptAlias /b '/path/to/project/g.wsgi'

<Location /a>
WSGIProcessGroup a
WSGIApplicationGroup %{GLOBAL}
</Location>

<Location /b>
WSGIProcessGroup b
WSGIApplicationGroup %{GLOBAL}
</Location>

</VirtualHost>
 在Windows中上面命令可能会遇到如下问题:
Invalid command 'WSGIDaemonProcess', perhaps misspelled or defined by a module not included in the server configuration
 这里因为
Daemon mode of mod_wsgi will however only be available on Apache 2.0 or 2.2 running on UNIX, and only when the Apache runtime library underlying Apache has been compiled with support for threading.
 
尝试使用:
<VirtualHost *:80>
WSGIScriptAlias /a /path/to/project/a.wsgi
WSGIScriptAlias /b /path/to/project/b/wsgi
</VirtualHost>
 并在代码中对环境变量做特异化处理:
 
import os
import site
import django.conf

django.conf.ENVIRONMENT_VARIABLE = 'DJANGO_A_SETTINGS_MODULE'

os.environ.setdefault('DJANGO_A_SETTINGS_MODULE', 'project_a.settings')

from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()
 结果有待测试,目前是这样子配置。

4、Django的目录结构

Django最佳实践
https://github.com/brantyoung/zh-django-best-practices

5、Django的运行命令

python manage.py runserver 0.0.0.0:80

6、Django-WSGI相关

https://code.google.com/p/modwsgi/wiki/IntegrationWithDjango

https://code.djangoproject.com/wiki/django_apache_and_mod_wsgi

以上是Django 与WSGI集成配置相关介绍。

Django+Wsgi集成与runserver之间的不同,见下文。

http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html

6、Django-Webproxy

Django的代理app

相关推荐

inspuryhq / 0评论 2020-07-28