Python Flask BuildError-无法为终结点生成URL
我有一个非常简单的python代码,可以从数据库中选择一些数据Python Flask BuildError-无法为终结点生成URL,python,html,flask,Python,Html,Flask,我有一个非常简单的python代码,可以从数据库中选择一些数据 @app.route('/studentsearch', methods = ['POST', 'GET']) def searchstudent(): """ Displays the student search page for the site """ cursor = mydb.cursor() cursor.execute ("SELECT * FROM student") all_stu
@app.route('/studentsearch', methods = ['POST', 'GET'])
def searchstudent():
""" Displays the student search page for the site """
cursor = mydb.cursor()
cursor.execute ("SELECT * FROM student")
all_students = cursor.fetchall()
cursor.close()
return render_template('studentsearch.html', all_students = all_students)
但当我去呈现HTML页面时,我得到了werkzeug.routing.BuildError:无法为端点“studentsearch”构建url。你是说“新闻学生”吗
我的桌子也很直
<table>
<thread>
<tr>
<th>Student ID:</th>
<th>First Name:</th>
<th>Last Name:</th>
<th>Click to View Student Details</th>
</tr>
</thread>
<tbody>
{% for each_result in all_students %}
<tr>
<td>{{ each_result[0] }}</td>
<td>{{ each_result[1] }}</td>
<td>{{ each_result[2] }}</td>
<td>CLICK HERE!!!</td>
</tr>
{% endfor %}
</tbody>
</table>
您是否正在尝试使用URL_for函数在应用程序代码或HTML代码中的某个位置构建动态URL 如果是,那么我认为可能发生的情况是将参数'studentsearch'传递给该函数,而不是'searchstudent'(url_用于使用视图函数名而不是端点名构建端点)。例如,在HTML模板中,相关URL的构建方式如下:
<a href="{{ url_for('searchstudent') }}">Search</a>
你能把你的app.py全部代码放上去吗?@code新手我的app.py全部代码大约有300行深,所以我不会把它全部放上去,但我已经添加了“newstudent”似乎要用到的代码
<a href="{{ url_for('searchstudent') }}">Search</a>