如何在使用python的heroku中使用postgresql连接时使用dj-database-url [英] How to use dj-database-url while connecting with postgresql in heroku using python
问题描述
我在这里是因为我真的对heroku-python-django-postgresql组非常熟悉。我已经搜索了dj-database-url的用法,但我不明白为什么在开发需要使用postgresql连接的python应用程序时必须使用它。我添加了postgresql(dev版本)作为我的应用程序的附加组件,但我不知道如何告诉应用程序我希望它使用我的db。
<所以,简单的问题是,我如何向dj-database-url表明我想使用我的数据库?
感谢您的时间和答案,我感谢您的帮助,因为这是非常非常紧迫的!
解决方案 dj-database-url是一个实用工具,数据库从DATABASE_URL环境变量导入到字典中。 Heroku使用你的数据库和其他插件的环境变量。要开始使用数据库,只需使用以下命令来设置DATABASES字典:
import dj_database_url
数据库['default'] = dj_database_url.config()
也许在你的virtualenv激活脚本中存放DATABASE_URL。
I'm here because I'm really really new with heroku-python-django-postgresql group. I have googled for a usage for dj-database-url and I don't understand why i have to use it when developing a python application that needs to connect with postgresql. I have added postgresql (dev version) as add-on to my application, but I don't know how to tell to the app that I want it to use my db.
so, the short question is, How do I indicate to dj-database-url that I want to use my database?
Thanks for your time and answers, I'll appreciate your help because this is very very urgent!
dj-database-url is a utility to help you load your database into your dictionary from the DATABASE_URL environment variable. Heroku uses environment variables for your database and other addons. To begin using your database you'd simply use the below command to setup your DATABASES dictionary:
import dj_database_url
DATABASES['default'] = dj_database_url.config()
And maybe stash DATABASE_URL in your virtualenv activate script.
这篇关于如何在使用python的heroku中使用postgresql连接时使用dj-database-url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!