【发布时间】:2014-07-18 15:44:54
【问题描述】:
我正在尝试让 Gunicorn 将 Python3 用于我想要制作的 Django 应用程序。我正在使用 Digital Ocean 的 Django 图像开始。它附带安装和配置的 Django、Gunicorn 和 Nginx。此图像附带的默认 Django 项目似乎适用于 Python 2。
我已经apt-get'ed 这些包。
- python3
- python3-psycopg2
- python3-dev
- python3-pip
为了尽量避免出现任何问题,我也这样做了。
- pip 卸载 django
- pip3 安装 django
我rm -rf'ed 了股票项目并使用django-admin.py startproject django_project 创建了一个新项目。 django-admin.py 使用 Python 3(根据 shebang)。后来我用python3 manage.py startapp django_app新建了一个app。
此时,一切正常。就像默认应用程序一样。然后,在django_app/views.py 我这样做了,它就坏了。
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
# Python 2 and 3 - works fine
# print('PRINTING')
# Python 3 only - crashes
print(1, 2, end=' ')
return HttpResponse("Hello, world! This is my first view.")
错误页面显示我使用的是 Python 2.7.6。
好的,所以我想我可以通过 pip 为 Python 3 安装 Gunicorn,所以我这样做了。
- pip 卸载 gunicorn
- pip3 安装 gunicorn
但后来我得到了 502 Bad Gateway。当我执行service gunicorn status 时,我得到gunicorn stop/waiting。我试过service gunicorn restart,但它仍然显示gunicorn stop/waiting。
我做了一个which gunicorn,它安装在/usr/local/bin/gunicorn。呃......我不确定我还能尝试什么。任何帮助将不胜感激。谢谢。
【问题讨论】:
标签: django python-2.7 python-3.x nginx gunicorn