ontariocourts311.ca左列中的列表以及图像下方的页面正文间歇性地无法显示(通过刷新页面进行“固定”)。我是Noob,并且尝试过各种版本的return语句,但均未成功。
错误:
2019-06-05 16:39:26,765: Exception on / [GET]
Traceback (most recent call last):
File "flask/app.py", line 2311, in wsgi_app
response = self.full_dispatch_request()
File "flask/app.py", line 1834, in full_dispatch_request
rv = self.handle_user_exception(e)
File "flask/app.py", line 1737, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "flask/_compat.py", line 36, in reraise
raise value
File "flask/app.py", line 1832, in full_dispatch_request
rv = self.dispatch_request()
File "flask/app.py", line 1818, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/mlesage/mysite/Court/application.py", line 40, in home
complaints = db.execute("SELECT User_Complaint, Date, Review_Title FROM Posts")
File "cs50/sql.py", line 224, in execute
raise e
RuntimeError: (MySQLdb._exceptions.OperationalError) (2013, 'Lost connection to MySQL server during query')
[SQL: SELECT User_Complaint, Date, Review_Title FROM Posts]
(Background on this error at: http://sqlalche.me/e/e3q8)
from cs50 import SQL
from helpers import contacts # (a list of people stored in helpers)
# Configure db to mySQL database
db = SQL("mysql://user.mysql.pythonanywhere-services.com:3306/user$User_Reviews")
#timeout = db.execute(con.query('SET GLOBAL connect_timeout=6000'))
@app.route("/", methods=["GET", "POST"])
def home():
reviews = [list of reviews, pulled from db, for display on page]
if request.method == "POST":
if User_Complaint != None:
return redirect ('/')
#return redirect(url_for('home', reviews = reviews, contacts = contacts))
else:
return render_template("home.html", reviews = reviews, contacts = contacts)
# GETS METHOD
else:
return render_template("home.html", reviews = reviews, contacts = contacts)
无论使用GETS还是POST方法,页面元素都应显示一致(即,左侧人员列表,页面中央和文本框的评论)。
答案 0 :(得分:0)
问题似乎与MySQL没有可用的开放连接有关,它似乎是通过对以下行稍加修改而解决的:
db = SQL(“ mysql:// user:password.mysql.pythonanywhere-services.com:3306 / user $ User_Reviews”,pool_recycle = 280)