如何在Heroku上为Django应用程序设置数据库? [英] How to set up database for Django app on Heroku?

查看:79
本文介绍了如何在Heroku上为Django应用程序设置数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个完整的Heroku noob,我试图在Heroku上设置一个Django应用程序。我无法弄清楚在settings.py中输入这些设置的内容:

I'm a complete Heroku noob and I'm trying to set up a Django app on Heroku. I can't figure out what to enter for these settings in settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': '',                      # Or path to database file if using sqlite3.
        # The following settings are not used with sqlite3:
        'USER': '',
        'PASSWORD': '',
        'HOST': '',                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
        'PORT': '',                      # Set to empty string for default.
    }
}

任何人都可以帮我吗?感谢您!

Can anybody help me out? Thank you!

推荐答案

您可以通过查看仪表板中的数据库信息或通过运行heroku config请参阅数据库配置字符串。但是,到目前为止,最好的方法详见 Heroku入门指南Django 。将 dj-database-url == 0.2.1 添加到 requirements.txt 文件中,然后:

You can do it manually by looking at your database info in the dashboard or by running "heroku config" to see the DB configuration string. But the best way by far is as detailed in the Heroku Getting Started guide for Django. Add dj-database-url==0.2.1 to your requirements.txt file and then:

# Parse database configuration from $DATABASE_URL
import dj_database_url
DATABASES['default'] =  dj_database_url.config()

代替其他数据库定义。

这篇关于如何在Heroku上为Django应用程序设置数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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