Python 为什么烧瓶闪光灯不工作?
这是我的python视图代码。我有一个闪光。但它不会显示任何类型的flash前端Python 为什么烧瓶闪光灯不工作?,python,flask,python-requests,Python,Flask,Python Requests,这是我的python视图代码。我有一个闪光。但它不会显示任何类型的flash前端 @auth.route('/admin/project/add',methods = ['POST', 'GET']) def addproject(): if request.method == 'POST': projectname = request.form['projectname'] c, conn = connection(
@auth.route('/admin/project/add',methods = ['POST', 'GET'])
def addproject():
if request.method == 'POST':
projectname = request.form['projectname']
c, conn = connection()
query = "SELECT Count(id) from projects WHERE project='{}'".format(projectname)
c.execute(query)
values = c.fetchall
conn.close()
if (values == 0):
flash("success")
return render_template('addproject.html')
else:
flash("Project already exists. Please goto projects page and confirm. If it is and error, please contact devloper.")
return render_template('addproject.html')
else:
return render_template('addproject.html')
在模板中,我添加了以下内容:
{% with messages = get_flashed_messages() %}
{% if messages %}
<ul>
{% for message in messages %}
<li><{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
{% endwith %}
需要执行:projectname
打字错误警报!检查闪存是否存在循环我更正了它..但我没有得到闪存可能与条件有关,请尝试在if request.method=='POST':之前放置一个闪存以检查我已尝试..它没有显示任何内容HTML部分我也检查了..因为它应该是从request.form首先获取数据,请尝试
from flask import flash, redirect, render_template, url_for, request
cur = conn.cursor()
query = """SELECT Count(id) from projects WHERE project= :project"""
cur.execute(query, project = projectname)