Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 获取从上一页单击的超链接的名称_Python_Html_Flask - Fatal编程技术网

Python 获取从上一页单击的超链接的名称

Python 获取从上一页单击的超链接的名称,python,html,flask,Python,Html,Flask,我正在创建一个关于考试的项目 在我的第一个html页面中,我有一组超链接,它们表示问题论文的名称。试题以表格的形式存储在MySQL中 我想要的是,在我的python代码中返回用户单击的超链接的名称 所有链接应指向同一网页,但每个链接中的内容不同 这是我的网页python代码,单击其中一个链接后应打开该网页: @app.route('/qsetdisplay/exam',methods=['GET','POST']) def exam(): if request.method == 'PO

我正在创建一个关于考试的项目

在我的第一个html页面中,我有一组超链接,它们表示问题论文的名称。试题以表格的形式存储在MySQL中

我想要的是,在我的python代码中返回用户单击的超链接的名称

所有链接应指向同一网页,但每个链接中的内容不同

这是我的网页python代码,单击其中一个链接后应打开该网页:

@app.route('/qsetdisplay/exam',methods=['GET','POST'])
def exam():
    if request.method == 'POST':
        if 'answer' in request.form:
            
            cursor5 = db3.cursor(pymysql.cursors.DictCursor)
            tablename = request.args.get('type')
           
            print(tablename)
            cursor5.execute("select questions from {}".format(tablename))
            
            cursor5.execute("select answers from {}".format(tablename))
           
            cursor5.execute("select marks from {}".format(tablename))
            print("ques:", ques)
            print("ans:", ans)
            print("marks:",marks)

    return render_template('exam.html',ques=ques,marks=marks,ans=ans)
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>EXAMINATION</title>
</head>
<body>
<div>
    <form name="ex" id="ex" action="{{url_for('exam')}}" method=POST>
        <h1 align="centre">ALL THE BEST!!!</h1>
        {% for que in ques %}
        <h6>{{que}}</h6>
        <textarea name="answer" id="answer" placeholder="enter answer"  rows="10" cols="100"></textarea><br><br>
        {% endfor %}
        <input name="sub" id="sub" type="submit" value="submit">

    </form>
</div>

</body>
</html>
tablename在上述代码中返回为none

这是我在点击其中一个链接后打开的网页的html代码:

@app.route('/qsetdisplay/exam',methods=['GET','POST'])
def exam():
    if request.method == 'POST':
        if 'answer' in request.form:
            
            cursor5 = db3.cursor(pymysql.cursors.DictCursor)
            tablename = request.args.get('type')
           
            print(tablename)
            cursor5.execute("select questions from {}".format(tablename))
            
            cursor5.execute("select answers from {}".format(tablename))
           
            cursor5.execute("select marks from {}".format(tablename))
            print("ques:", ques)
            print("ans:", ans)
            print("marks:",marks)

    return render_template('exam.html',ques=ques,marks=marks,ans=ans)
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>EXAMINATION</title>
</head>
<body>
<div>
    <form name="ex" id="ex" action="{{url_for('exam')}}" method=POST>
        <h1 align="centre">ALL THE BEST!!!</h1>
        {% for que in ques %}
        <h6>{{que}}</h6>
        <textarea name="answer" id="answer" placeholder="enter answer"  rows="10" cols="100"></textarea><br><br>
        {% endfor %}
        <input name="sub" id="sub" type="submit" value="submit">

    </form>
</div>

</body>
</html>

检查
祝你一切顺利!!!
{que中que的百分比%}
{{que}


{%endfor%}
这是上一页的html代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>STUDENT PROFILE</title>
</head>
<body>
<div>
    <form action="/">
         <h1>"WELCOME STUDENT"</h1>
    </form>
</div>

<div>
    <form name="QD" action="{{url_for('qset_display')}}" method="get">
        <input name="QD" value="CLICK TO VIEW QUES PAPERS" type="submit"><br><br><br><br>
        <h1>THESE ARE THE AVAILABLE PAPERS:</h1>
        {% for name in names %}
        <a href="{{ url_for('exam', type=name) }}">{{name}}</a><br><br>
        {% endfor %}
    </form>
</div>
</body>
</html>

学生资料
“欢迎学生”




以下是可用的文件: {名称中的名称为%}

{%endfor%}

如何更正我的代码?

您必须以某种方式将
名称
(URL转义)的文本作为路径的一部分或作为参数(在
之后)放在URL中。如何执行,先生?