【问题标题】:Type error whil connecting mysql and flask连接mysql和flask时输入错误
【发布时间】:2022-12-17 07:14:48
【问题描述】:
from flask import Flask, render_template, request, redirect, url_for, flash
from flask_mysqldb import *

app = Flask(__name__)
app.secret_key = 'many random bytes'

app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_PORT'] = '3800'
app.config['MYSQL_USER'] = 'root'
app.config['MYSQL_PASSWORD'] = 'root'
app.config['MYSQL_DB'] = 'practicle'

mysql = MySQL(app)


@app.route('/')
def Index():
    cur = mysql.connection.cursor()
    cur.execute("SELECT  * FROM students")
    data = cur.fetchall()
    cur.close()
    return render_template('index2.html', students=data )

#这是我尝试运行的代码,但是一旦服务器启动,就会发生错误 #类型错误 #TypeError: 'str' 对象不能解释为整数

#在行中: #cur = mysql.connection.cursor()

#然而这个程序没有使用类型转换 #请帮我解决这个问题

【问题讨论】:

    标签: python


    【解决方案1】:

    espero que este bien。 Estoy tambien aprendiendo sobre flask, hace un tiempo me paso algo similar, favor de intar con el siguiente codigo, para mostrar mas detalle del error y vas a poder corregirlo.萨鲁多斯。

    定义指数(): 数据 = {} 尝试: 游标 = mysql.connection.cursor() sql = "SELECT * FROM 学生" 游标.执行(sql) empresas = cursor.fetchall() 打印(empresas) 除了作为错误的异常: 打印(f“意外{错误=},{类型(错误)=}”) 返回数据

    【讨论】:

      猜你喜欢
      • 2019-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-28
      • 2018-07-30
      • 2018-11-02
      • 2015-10-11
      • 1970-01-01
      相关资源
      最近更新 更多