Python Heroku/Django:没有名为 dj_database_url 的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12683367/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 11:35:49  来源:igfitidea点击:

Heroku/Django: No module named dj_database_url

pythondjangopostgresqlheroku

提问by zhuyxn

I'm trying to set up PostgresSQL for the first time on Django, running into this error when I try to do a syndb?

我第一次尝试在 Django 上设置 PostgresSQL,当我尝试执行 Syndb 时遇到了这个错误?

ImportError: Could not import settings 'testapp.settings' (Is it on sys.path?):

导入错误:无法导入设置“testapp.settings”(是否在 sys.path 上?):

Also have this at the toop of my settings.py file, no idea if this is correct?

也有这个在我的 settings.py 文件的顶部,不知道这是否正确?

import dj_database_url
DATABASES = {'default': dj_database_url.config(default=os.environ.get('DATABASE_URL'))}

回答by Kenneth Reitz

You have to install dj-database-url.

您必须安装 dj-database-url。

Add it to your requirements.txt file.

将其添加到您的 requirements.txt 文件中。

回答by David S

You don't give a lot of information about exactly where you are trying to run your sync db? Locally? Or up on Heroku? My answer is going to assume that it's locally.

您没有提供大量有关您尝试运行同步数据库的确切位置的信息?本地?还是在 Heroku 上?我的回答是假设它是本地的。

Basically, you need to have virtualenv install and pip. While working in your virtualenv (with it activated), you need to do a

基本上,您需要安装 virtualenv 和 pip。在您的 virtualenv 中工作(激活它)时,您需要执行

 pip install dj-database-url

Then you need to do a:

然后你需要做一个:

 pip freeze > requirements.txt

Getting up and going on Python+Django+Heroku is not a really hard thing to do... but, there are quite a few steps. If you are fuzzy, I recommend the Heroku Django tutorial.

开始并继续使用 Python+Django+Heroku 并不是一件很难的事情……但是,有很多步骤。如果你不清楚,我推荐 Heroku Django教程