Heroku数据库设置注入 - 如何设置我的dev django数据库? [英] Heroku Database Settings Injection - How do I setup my dev django database?
问题描述
我遵循说明,但是当我的应用程序尝试访问本地数据库时,会出现以下错误。
请求方法:GET
请求URL:http:// localhost:8000
Django版本:1.4
异常类型:不正确配置
异常值:
您需要在Django设置文件中指定NAME。
最初的数据库设置
DATABASES = {
'default':{
'ENGINE':'django.db.backends.postgresql_psycopg2',
'NAME':'db' #或使用sqlite3的数据库文件路径。
'USER':'foo',#不与sqlite3一起使用。
'PASSWORD':'bar',#不与sqlite3一起使用。
'HOST':'localhost',
'PORT':'5432',
}
}
英雄文章说要在设置文件中添加以下内容
import dj_database_url
DATABASES = {'default':dj_database_url.config(default ='postgres:// localhost')}
当DATABASE_URL在dev中不可用时,如何使dj_database_url.config使用我的dev设置?
您可以将开发人员设置添加到这样的默认值...
import dj_database_url
DATABASES = {'default':dj_database_url.config(default ='postgres:// foo:bar @ localhost:5432 / db')}
I'm trying to get my local dev django app to work after following these instructions on adding env database settings.
https://devcenter.heroku.com/articles/django-injection
I followed the instructions but get the following error when my app tries to access the local database
Request Method: GET
Request URL: http://localhost:8000
Django Version: 1.4
Exception Type: ImproperlyConfigured
Exception Value:
You need to specify NAME in your Django settings file.
My database settings originally,
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'db', # Or path to database file if using sqlite3.
'USER': 'foo', # Not used with sqlite3.
'PASSWORD': 'bar', # Not used with sqlite3.
'HOST': 'localhost',
'PORT': '5432',
}
}
the heroku article says to add the following to the settings file
import dj_database_url
DATABASES = {'default': dj_database_url.config(default='postgres://localhost')}
how do I get dj_database_url.config to use my my dev settings when the DATABASE_URL is not available in dev?
You can just add your dev settings to the default values like this...
import dj_database_url
DATABASES = {'default': dj_database_url.config(default='postgres://foo:bar@localhost:5432/db')}
这篇关于Heroku数据库设置注入 - 如何设置我的dev django数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!