python 我正在将变量返回到“培养瓶视图”,但我希望显示时不使用方括号或单引号

jw5wzhpr  于 2023-02-28  发布在  Python
关注(0)|答案(1)|浏览(75)

我的HTML格式如下:
index.html

{% block form_action %}

<form action = "/login" method = "post">
    <p>First Name:</p>
    <p><input type = "text" name = "fnm" /></p>
    <p>Last Name:</p>
    <p><input type = "text" name = "lnm" /></p>

    <p><input type = "submit" value = "submit" /></p>
 </form>

{% endblock form_action %}

contact.html

{% block form_action %}

<p>Entered Name:</p>
<p> {{ last_name, user_name}} </p>

{% endblock form_action %}

python函数:

@app.route('/login',methods = ['GET','POST'])
def login():

if request.method ==  'POST':
    fnm = request.form['fnm']  #first name
    lnm = request.form['lnm']
    return render_template('contact.html',user_name = fnm,last_name = lnm)

它输出下拉菜单,如图所示-我希望显示它时不带括号/引号-任何帮助都非常感谢。image

bq3bfh9z

bq3bfh9z1#

谢谢大家的回答我想到了什么
Contact.html

{% block form_action %}

 <p>Entered Name:</p>
 <p> {{ last_name}} {{user_name}} </p>

 {% endblock form_action %}

在这里,我更改了模板中的{{last_name}}、{{user_name}}-换句话说,两次单独替换字符串,而不是一次替换元组{{last_name,user_name}}

相关问题