【发布时间】: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