下記の質問をさせていただいた者ですが、原因が絞れてきたので、別途質問を上げさせていただきます。
https://teratail.com/questions/54048
VPS上でDjangoのアプリを公開しています。
サーバーのOS:Ubuntu 16.04.1 LTS
Pythonのバージョン:3.5.2
Djangoのバージョン:1.10.3
Djangoアプリを起動するにあたり、Gunicorn+nginxで動かしています。
今まで、Python2系で開発していたため、
models.pyは、下記のように、unicodeと書いていました。
python
1# python2系の時 2class Sample(models.Model): 3 id = models.IntegerField(primary_key=True) 4 name = models.CharField(max_length=40) 5 def __unicode__(self): 6 return self.name
Python3に変えるにあたって、下記のようにstrを用いる形に変更しました。
python
1# python3に変えた後 2class Sample(models.Model): 3 id = models.IntegerField(primary_key=True) 4 name = models.CharField(max_length=40) 5 def __str__(self): 6 return self.name
そして、本番環境においても、Python3.5.2がデフォルトなので、
python manage.py runserver
でアプリを起動した場合は問題なくPython3で起動するのですが、
gunicorn -w 1 -b 127.0.0.1:8000 example.wsgi
という形でGunicornを起動すると、
Python2が呼び出されてしまいます。
そのため、エラーが生じてしまっていました。
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 515, in spawn_worker
worker.init_process()
というエラーが出ていたため、気づきました。
どのようにしたら、Gunicornで起動してもPython3系として動いてくれるでしょうか?
お分かりの方、よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー