对于部署服务器安装很有用。添加管理命令以对项目进行配置。自动识别三方应用程序中的媒体目录
django-server-config的Python项目详细描述
- 添加管理命令以对项目进行配置。 现在它可以为lighttpd、logrotate、monit和deploy脚本生成配置。
- 自动识别三方应用程序中的媒体目录并将其考虑在内。
安装:
在设置中。py:
把config放到INSTALLED_APPS中。
为项目设置域名
CONFIG_SITES = ['www.project-name.com', ]
要重定向到站点的域
CONFIG_REDIRECTS = ['project-name.com', ]
提供静态文件
Set path to media for unusual 3-party application
CONFIG_APP_MEDIA = { 'application-name': [ ('media-root', 'media-url', ), ] }
Media folders with same name as application modulde will be added automatically. For example, in ^{tt3}$ module media files
tinymce/ media/ tinymce/ js/tinymce.js css/style.css
will be available at url:
/media/tinymce/js/tinymce.js /media/tinymce/css/style.js
停止!django staticfiles不是这么做的吗?
是的,他们有。但是django servre config比staticfiles旧,并且做相同的工作。此功能将被弃用,并且自0.2.x版本起将不受支持。我们建议使用django contrib applicationdjango.contrib.statifiles。请阅读下面的操作说明。
在url.py中:
如果使用django-server-config为静态媒体提供服务,请在url.py中为调试模式下的静态文件提供服务添加以下代码。在django.views.static.serve
if settings.DEBUG: urlpatterns += patterns('', (r'^', include('config.urls')))
内置.cfg:
如果您使用的是zc.buildout,则可以将make-config添加到您的部件中,使配置文件自动生效:
[make-config] recipe = iw.recipe.cmd on_install = true on_update = true cmds = sudo rm -f bin/init.d bin/lighttpd bin/logrotate bin/monit bin/*.py bin/django make_config init.d > bin/init.d bin/django make_config lighttpd > bin/lighttpd bin/django make_config logrotate > bin/logrotate bin/django make_config monit > bin/monit # Enable backups with duply & duplicity (http://duplicity.nongnu.org) bin/django make_config duply_conf > bin/duply_conf bin/django make_config duply_pre > bin/duply_pre bin/django make_config duply_post > bin/duply_post bin/django make_config duply_exclude > bin/duply_exclude # Collect static automaticaly sudo rm -Rf static bin/django collectstatic -l ---noinput sudo chown www-data:www-data -R static bin/django make_config install.py > bin/install.py bin/django make_config uninstall.py > bin/uninstall.py bin/django make_config enable.py > bin/enable.py bin/django make_config disable.py > bin/disable.py sudo chown root:root bin/* sudo chmod ug=rw,o=r bin/* sudo chmod ug=rwx,o=rx bin/init.d bin/django bin/buildout echo Configs were saved to "bin/"
不含bulidout
如果不使用zc.buildlout,可以使用上面的命令添加到repository shell脚本中,它将产生相同的效果。
静态文件支持
因为0.1.1服务器配置支持django.contrib.staticfiles和staticfiles应用程序。如果其中一个出现在INSTALLED_APPS中,则将使用适当的重写规则生成web服务器的配置。
如果使用staticfiles,则无需在urlconf.py中包含config.urls。另一方面,您可能希望包含staticfiles应用程序中的staticfiles_urlpatterns()(请参见:django documentation关于它)
from django.contrib.staticfiles.urls import staticfiles_urlpatterns urlpatterns += staticfiles_urlpatterns()
重复/重复备份
django服务器配置可以自动创建备份配置文件。 它支持duply(duplicity)配置方案。 duplicity是用python编写并使用rsync算法的备份系统,duply是duplicity的bash配置包装器。
备份设置
安全说明
要开始使用备份,应指定duply主配置文件的路径。django服务器配置要求文件格式为*.ini。此文件 可以包含机密密码,因此文件应该位于/etc/duply/conf.ini中的某个位置,并且属于根用户(超级用户)。
- 备份配置
- 重复配置文件的路径
- 备份温度目录
- temp目录,数据库备份将位于其中。每次备份会话后,将从文件系统中删除数据库转储。默认值:'/var/backups/postgres'
只支持PostgreSQL数据库备份!
双重配置文件
重复配置非常简单。 只需从命令行::
duply <profile> create
然后查看~/.duply/<;profile>;/conf并按照注释进行操作。
此外,您还可以使用我们的配置模板:
[duply] GPG_PW='**********' TARGET='s3+http://**********@com.mycompany.server/' SOURCE='/' MAX_AGE=1M MAX_FULL_BACKUPS=5 MAX_FULLBKP_AGE=1W VOLSIZE=50 DUPL_PARAMS="$DUPL_PARAMS --full-if-older-than $MAX_FULLBKP_AGE --volsize $VOLSIZE "
此模板使用gpg加密备份并上传到amazons3 bucketcom.mycompany.server。
注意TAGET选项。django服务器配置将自动将项目名添加到TARGET。例如,呈现的配置将包含值:
TARGET = s3+http://**********@com.mycompany.server/<myproject>
考虑一下*.iniconfig中的尾随斜杠,django server config只添加myproject而不添加斜杠。
历史记录
- 0.1.0-初始提交
- 0.1.1-添加了静态文件支持
- 0.1.2-双备份支持
- 0.1.3-紧急lighttpd配置修复(静态文件不工作),不要使用v0.1.1!
- 修复了没有静态文件的工作