django - Run manage.py with custom database configuration
问题描述
My use case involves running python manage.py migrate
with DATABASE_HOST=127.0.0.1
(since I use Cloud SQL Proxy). However, when the application is uploaded and is serving, the database URL needs to change to an actual remote URL.
Right now, I upload a special settings.py
file that contains the localhost URL when I wish to run the migration command. When I deploy to cloud, I make sure to overwrite that file with a new one (which is essentially the entire file except the database URL is my remote db URL) and then upload it.
Is there a better way to achieve this? Something like python manage.py --database_url=127.0.0.1 migrate
?
解决方案
Maybe you should try making a separate file, let's say local_settings.py, in the settings.py directory. In that file copy the ALLOWED_HOSTS =["your IP"]. Then in your settings.py import it as form try: .local_settings import * except: pass But keep the ALLOWED_HOSTS=[ ] in your settings.py as it is. Hope it helps!
推荐阅读
- java - java.net.SocketException:DNS 刷新后未解析的地址
- batch-file - COPY 命令 - .BAT 文件内的 STDERR 重定向出现意外结果
- python - 有没有一种好方法可以让一个类从两个类之一继承
- javascript - 绘制从 Firebase-Database 检索的数据(实时)
- visual-studio-code - 从当前光标位置获取语言特定范围
- python - 如何使用 brython 创建交互式 python 脚本编写器
- c# - 一个属性的显示名称(标签)是否会根据另一个属性的值而改变?
- java - 有什么方法可以从字符串中提取数字并在中间使用 lambda java 列表添加一些文本
- python - 如何在 windows10 上安装 hunspell?
- jupyter-notebook - Jupyter Notebooks 中的字母列表