首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“从flaskext.mysql导入MySQL”导致服务器显示502坏网关。

“从flaskext.mysql导入MySQL”导致服务器显示502坏网关。
EN

Stack Overflow用户
提问于 2019-02-21 23:35:14
回答 1查看 414关注 0票数 0

刚接触到蟒蛇。以下是使用Python3.6.7、烧瓶、Gunicorn、NGINX和MySQL在Ubuntu18.04上为应用程序(MySQL)服务的几个教程

这些教程是:

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安装烧瓶-mysql。

我的笔尖冻结显示:

代码语言:javascript
复制
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. from flask.ext.mysql import MySQL
  2. from flaskext.mysql import MySQL
  3. from flask_mysql import MySQL
  4. from flaskext.mysql import MySQL

1、2和3都生成ModuleNotFoundError... --唯一不抛出错误的是from flaskext.mysql import MySQL

但是,当我将from flaskext.mysql import MySQL添加到我的烧瓶应用程序文件(app01.py)中时,我立即得到一个502错误的网关错误。我的app01.py文件是

代码语言:javascript
复制
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错误消失,以便我连接到数据库是非常感激的。谢谢。

EN

回答 1

Stack Overflow用户

发布于 2019-02-22 01:58:08

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

之前的类似问题:ImportError:没有名为flask.ext.mysql的模块

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54817890

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档