Mezzanine+Gunicornがエラーを吐いている件のメモ


エラーその1
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.

は、sttings.pyに、同じディレクトリににあるlocal_settings.pyの中の
SECRET_KEY = “~~~”
の行をコピーしたら解消された。

エラーその2
File "/usr/local/lib/python3.4/site-packages/south/models.py", line 2, in
from south.db import DEFAULT_DB_ALIAS
File "/usr/local/lib/python3.4/site-packages/south/db/__init__.py", line 84, in
db = dbs[DEFAULT_DB_ALIAS]
KeyError: 'default'

sttings.pyのDATABASESの部分を変更したら解消された。

DATABASES = {
"default": {
# Ends with "postgresql_psycopg2", "mysql", "sqlite3" or "oracle".
"ENGINE": "django.db.backends.sqlite3", # sqlite3を追加
# DB name or path to database file if using sqlite3.
"NAME": "dev.db", # dev.dbを追加

参考:Getting “ImproperlyConfigured: The SECRET_KEY setting must not be empty.” error when deploying mezzanine 3.0.9 on openshift – codeitive.com

エラーその3
/usr/local/lib/python3.4/site-packages/mezzanine/utils/conf.py:52: UserWarning: You haven't defined the ALLOWED_HOSTS settings, which Django 1.5 requires. Will fall back to the domains configured as sites.
warn("You haven't defined the ALLOWED_HOSTS settings, which "
/usr/local/lib/python3.4/site-packages/mezzanine/utils/conf.py:60: UserWarning: TIME_ZONE setting is not set, using closest match: UTC
warn("TIME_ZONE setting is not set, using closest match: %s" % tz)

sttings.pyのTIME_ZONEを修正。
TIME_ZONE = ‘Asia/Tokyo’
参考:How to use Mezzanine on PythonAnywhere – PythonAnywhe

エラーその4
/usr/local/lib/python3.4/site-packages/mezzanine/utils/conf.py:52: UserWarning: You haven't defined the ALLOWED_HOSTS settings, which Django 1.5 requires. Will fall back to the domains configured as sites.
warn("You haven't defined the ALLOWED_HOSTS settings, which "

ALLOWED_HOSTSを設定しないといけないみたい。設定すると、そのドメインの設定がさらに求められる。
Traceback (most recent call last):
File "/usr/local/lib/python3.4/site-packages/gunicorn/workers/sync.py", line 130, in handle
self.handle_request(listener, req, client, addr)
File "/usr/local/lib/python3.4/site-packages/gunicorn/workers/sync.py", line 171, in handle_request
respiter = self.wsgi(environ, resp.start_response)
File "/usr/local/lib/python3.4/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
self.load_middleware()
File "/usr/local/lib/python3.4/site-packages/django/core/handlers/base.py", line 44, in load_middleware
for middleware_path in settings.MIDDLEWARE_CLASSES:
File "/usr/local/lib/python3.4/site-packages/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/usr/local/lib/python3.4/site-packages/django/conf/__init__.py", line 49, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python3.4/site-packages/django/conf/__init__.py", line 128, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/local/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 2254, in _gcd_import
File "", line 2237, in _find_and_load
File "", line 2226, in _find_and_load_unlocked
File "", line 1200, in _load_unlocked
File "", line 1129, in _exec
File "", line 1471, in exec_module
File "", line 321, in _call_with_frames_removed
File "/home/ec2-user/gunimezzanine/settings.py", line 97, in
ALLOWED_HOSTS = [amazonaws.com]
NameError: name 'amazonaws' is not defined

で、setting.pyのDEBUGをTrueにすると解消される。
DEBUG = True
もう少し調査。

で、ALLOWED_HOSTSを以下の設定にしたら、動いた。
ALLOWED_HOSTS = [
'.http://ec2-xx-xx-xxx-xxx.ap-northeast-1.compute.amazonaws.com/',
'.http://ec2-xx-xx-xxx-xxx.ap-northeast-1.compute.amazonaws.com/.',
]

レイアウト崩れているけど。
スクリーンショット 2015-05-13 00.19.41

参考:How To Install And Get Started With Django-Based Mezzanine CMS on Ubuntu | DigitalOcean

レイアウト崩れを治す方法

manage.pyのディレクトリに移動して、

python3 manage.py collectstatic

とすると、staticのディレクトリにいろいろと保存されます。

スクリーンショット 2015-05-13 18.05.03

これでgunicornを起動すると、レイアウト崩れが解消されます。

Nginxで動かす時は、
Nginx+Gunicorn+AWSでDjangoの起動画面を表示するまでのメモ | kazsoga(曽我一弘)ブログ
Nginx+Gunicorn+AWSでDjangoのadmin画面が崩れているのを修正した時のメモ | kazsoga(曽我一弘)ブログ
と同じ作業をすれば動作する。