如何配置Django进行简单的开发和部署? [英] How do you configure Django for simple development and deployment?

查看:154
本文介绍了如何配置Django进行简单的开发和部署?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 SQLite 使用 Django
开发,但是在一个实时服务器上,更强大的是
通常需要( MySQL / 例如PostgreSQL )。
总体而言,Django
设置还有其他变化:不同的日志记录位置/强度,
媒体路径等。

I tend to use SQLite when doing Django development, but on a live server something more robust is often needed (MySQL/PostgreSQL, for example). Invariably, there are other changes to make to the Django settings as well: different logging locations / intensities, media paths, etc.

如何管理所有这些更改以使部署成为
简单的自动化流程?

How do you manage all these changes to make deployment a simple, automated process?

推荐答案

更新: django配置已经发布,这可能是一个更好的选择对于大多数人而不是手动执行。

Update: django-configurations has been released which is probably a better option for most people than doing it manually.

如果您希望手动进行某些操作,我早期的答案仍然适用:

If you would prefer to do things manually, my earlier answer still applies:

我有多个设置文件。


  • settings_local.py - 主机特定配置,如数据库名称,文件路径等。

  • settings_development.py - 用于开发的配置,例如 DEBUG = True

  • settings_production.py - 用于生产的配置,例如 SERVER_EMAIL

  • settings_local.py - host-specific configuration, such as database name, file paths, etc.
  • settings_development.py - configuration used for development, e.g. DEBUG = True.
  • settings_production.py - configuration used for production, e.g. SERVER_EMAIL.

> settings.py 文件,首先导入 settings_local.py ,然后另外两个。它决定在 settings_local.py - DEVELOPMENT_HOSTS PRODUCTION_HOSTS settings.py 调用 platform.node()以查找正在运行的机器的主机名,然后查看对于列表中的该主机名,并加载第二个设置文件,具体取决于哪个列表中找到主机名。

I tie these all together with a settings.py file that firstly imports settings_local.py, and then one of the other two. It decides which to load by two settings inside settings_local.py - DEVELOPMENT_HOSTS and PRODUCTION_HOSTS. settings.py calls platform.node() to find the hostname of the machine it is running on, and then looks for that hostname in the lists, and loads the second settings file depending on which list it finds the hostname in.

这样,您唯一需要担心的是使用主机特定的配置保持 settings_local.py 文件的最新状态,其他一切都会自动处理。

That way, the only thing you really need to worry about is keeping the settings_local.py file up to date with the host-specific configuration, and everything else is handled automatically.

查看示例此处

这篇关于如何配置Django进行简单的开发和部署?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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