gpt4 book ai didi

mysql - "from flaskext.mysql import MySQL"导致服务器显示 502 bad gateway

转载 作者:行者123 更新时间:2023-11-29 16:15:42 24 4
gpt4 key购买 nike

Python 新手。按照几个教程在 Ubuntu 18.04 上使用 Python 3.6.7、Flask、Gunicorn、NGINX 和 MySQL 来提供应用程序 ( ddworkflow.com )

教程是:

https://philchen.com/2019/02/11/how-to-make-a-python-web-app-in-virtualenv-using-flask-gunicorn-nginx-on-ubuntu-18-04

https://code.tutsplus.com/tutorials/creating-a-web-app-from-scratch-using-python-flask-and-mysql--cms-22972

我完成了第一个教程,并且能够成功地提供第二个教程中的基本网页。

在虚拟环境中安装所有内容,并且刚刚使用 pip install Flask-mysql 安装了 Flask-mysql。

我的点卡住显示:

Click==7.0
Flask==1.0.2
Flask-MySQL==1.4.0
itsdangerous==1.1.0
Jinja2==2.10
MarkupSafe==1.1.0
PyMySQL==0.9.3
Werkzeug==0.14.1

安装Flask-MySQL后,我通过尝试“from”命令的以下不同变体(在python提示符下)来测试安装:

  1. 从flask.ext.mysql导入MySQL
  2. 从flaskext.mysql导入MySQL
  3. 从flask_mysql导入MySQL
  4. 从flaskext.mysql导入MySQL

1、2 和 3 都会产生 ModuleNotFoundError... 唯一不抛出错误的是 fromflaskext.mysql import MySQL

但是,当我将 from Flaskext.mysql import MySQL 添加到我的 Flask 应用程序文件 (app01.py) 时,我立即收到 502 bad gateway 错误。我的 app01.py 文件是

from flask import Flask, render_template, json, request
#from flaskext.mysql import MySQL #<--comment out or get 502 error
hello = Flask(__name__)

@hello.route("/")
def greeting():
return render_template('index.html')

@hello.route('/showSignUp')
def showSignUp():
return render_template('signup.html')

@hello.route('/signUp',methods=['POST'])
def signUp():
# read the posted values from the UI
_name = request.form['inputName']
_email = request.form['inputEmail']
_password = request.form['inputPassword']

# validate the received values
if _name and _email and _password:
return json.dumps({'html':'<span>All fields good !!</span>'})
else:
return json.dumps({'html':'<span>Enter the required fields</span>'})

if __name__ == "__main__":
hello.run(host='0.0.0.0')

非常感谢任何帮助我消除 502 错误以便我连接到数据库的信息。谢谢。

最佳答案

这可能是 virtualenv 错误,请查看此链接:https://www.pythonanywhere.com/forums/topic/2877/

之前的问题非常相似:ImportError: No module named flask.ext.mysql

关于mysql - "from flaskext.mysql import MySQL"导致服务器显示 502 bad gateway,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54817890/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com