6

回答へのコメントで、誰かがこの質問をしました。しかし、答えはまだ不明です。

Heroku で django サイトを実行していますが、Postgresql と連携するにはdj-database-urlモジュールが必要です。ローカル コンピューターのsettings.pyでDATABASES = dj-database-url()を使用して django を実行するにはどうすればよいですか? Heroku にプッシュする前にコードを変更するのは、かなり醜い方法です。

4

1 に答える 1

19

There are many ways to handle different production / development environments.

One is to have a local settings file that's imported at the bottom of your settings file that's not in version control, and thus not in heroku.

Another is any way to distinguish heroku environment from your local environment. An arbitrary environment variable, for example.

Another, is the default argument passed to dj_database_url which basically does this simple if statement for you.

import dj_database_url
DATABASES['default'] = dj_database_url.config(
    default='sqlite:////path-to-my/database.sqlite')

Remember, this settings file is just python. You could have it use one database on Tuesday for example.. any if statement you can come up with will work.

于 2012-12-06T04:16:37.820 に答える