为什么Flask闪光不起作用?

2024-09-25 00:30:35 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的python视图代码。我有闪光点。但它不会显示任何类型的flash前端。在

  @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')      

在模板中,我添加了以下内容:

^{pr2}$

有人能帮我解决这个问题吗? 也可以这样做:

from flask import flash, redirect, render_template, url_for, request

Tags: fromprojectreturnifrequesthtmltemplaterender