Pythonanywhereの支払いアカウントにある私のpostgresqlデータベースに私のDjango Webアプリケーションデータベースを接続したいと思います。何かをコーディングする前に、私はすべてのことをお互いに話したいと思っていました。これは、私のdjangoアプリケーションのsettings.pyデータベースセクションです。私はPython 3.5とDjango 1.9を実行しています。我々は両方のタブDATABASEとPostgresの下pythonanywhere.comサイトから提供しているDjango WebアプリケーションデータベースをPythonanywhereのpostgresqlに接続する
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': '[myDatabaseName]',
'USER': '[myUsername]',
'PASSWORD': '[myPassword]',
'HOST': 'xxxxxxxx-xxx.postgres.pythonanywhere-services.com',
'PORT': '10130',
}
}
HOSTとPORT。 Postgresコンソールでデータベース、ユーザ名、パスワードを作成しました。
私は、postgresデータベースとの接続が機能しているかどうかを確認するためにcheckb.pyスクリプトを作成しました。
from django.db import connections
db_conn = connections['default']
try:
c = db_conn.cursor()
except OperationalError:
connected = False
else:
connected = True
これは、このコードを実行した後に表示されるエラーです。
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/django/conf/__init__.py", line 38, in _setup
settings_module = os.environ[ENVIRONMENT_VARIABLE]
File "/usr/lib/python3.4/os.py", line 633, in __getitem__
raise KeyError(key) from None
KeyError: 'DJANGO_SETTINGS_MODULE'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/giraldez/golf/golf/dbcheck.py", line 2, in <module>
db_conn = connections['default']
File "/usr/local/lib/python3.4/dist-packages/django/db/utils.py", line 196, in __getitem__
self.ensure_defaults(alias)
File "/usr/local/lib/python3.4/dist-packages/django/db/utils.py", line 170, in ensure_defaults
conn = self.databases[alias]
File "/usr/local/lib/python3.4/dist-packages/django/utils/functional.py", line 49, in __get__
res = instance.__dict__[self.func.__name__] = self.func(instance)
File "/usr/local/lib/python3.4/dist-packages/django/db/utils.py", line 153, in databases
self._databases = settings.DATABASES
File "/usr/local/lib/python3.4/dist-packages/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/usr/local/lib/python3.4/dist-packages/django/conf/__init__.py", line 47, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting DATABASES, but settings are not configured. You must either define the environment variable D
JANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
私のプロジェクトのディレクトリには、スタンドアロンスクリプトとして、それを使用している場合は、最初のセットアップジャンゴする必要があり、この
golf/
---golf/
------__init.py__
------dbcheck.py
------settings.py
------urls.py
------wsgi.py
---media/
---static/
---manage.py
INSTALLED_APPS sttings変数にインストールされているすべてのアプリがインストールされていることを確認しましたか? –