Issue
- I have a
users
table given below. I am trying to update field valueapproved
for the same.
- I have defined the method in
app.py
and have written a simple update query but after clicking on the button I am facing the errorThe requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
app.py
@app.route('/approve_student',methods = ['GET','POST'])
def approve_student(student_email):
connection = psycopg2.connect(user="root",
password="root",
host="localhost",
port="5432",
database="proctoring")
cursor = connection.cursor()
student_email = student_email
sql = """ UPDATE student
SET approved = %s
WHERE emailid = %s"""
cursor.execute(sql, (True, student_email))
return redirect(url_for('admin-dashboard'))
- HTML
{% for row in data %}
...
<td>
{% if row[5] == False %}
<a href="{ url_for('approve_student', student_email=row[4] }" title="Approve">
<i class="material-icons" style="font-size:16px">Approve</i></a>
...
{% endfor %}
Solution
You did,
@app.route('/approve_student',methods = ['GET','POST'])
def approve_student(student_email):
The first line suggests you do not want any parameters in the path. The second line suggests you want one parameter called student_email
. If last is the case please try the following:
@app.route('/approve_student/<student_email>',methods = ['GET','POST'])
def approve_student(student_email):
You are also missing a few brackets in the href
of your <a>
tag. Try changing it to the following:
href="{{ url_for('approve_student', student_email=row[4]) }}"
Answered By - Daweo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.