我正在使用flask做一个Web应用程序,有一点是一种获取值的形式,如下所示:
Pattern.html
{% extends "base.html" %}
{% block body %}
<form action="/patterns" method="post" enctype="multipart/form-data" >
<div class="form-group">
<label for="pattern_name">Nome do padrão</label>
<input class="form-control" id="pattern_name_input" name="pattern_name_input" aria-describedby="pattern_name_help" placeholder="Nome do Padrão" required="required" >
<small id="pattern_name_help" class="form-text text-muted">Nome do padrão. Este valor será usado como entrada no dataframe.</small>
</div>
<div class="form-group">
<label for="pattern_head">Inicio do Padrão</label>
<input class="form-control" id="pattern_head_input" name="pattern_head_input" aria-describedby="pattern_head_help" placeholder="Início do padrão" >
<small id="pattern_head_help" class="form-text text-muted">Início do padrão. O padrão será composto por inicio+meio+fim.</small>
</div>
<div class="form-group">
<label for="pattern_middle">Meio do Padrão</label>
<input class="form-control" id="pattern_middle_input" name="pattern_middle_input" aria-describedby="pattern_middle_help" placeholder="Meio do Padrão" >
<small id="pattern_middle_help" class="form-text text-muted">Meio do padrão. O padrão será composto por inicio+meio+fim.</small>
</div>
<div class="form-group">
<label for="pattern_tail">Fim do Padrão</label>
<input class="form-control" id="pattern_tail_input" name="pattern_tail_input" aria-describedby="pattern_tail_help" placeholder="Fim do Padrão" >
<small id="pattern_tail_help" class="form-text text-muted">Fim do padrão. O padrão será composto por inicio+meio+fim.</small>
</div>
<button type="submit" class="btn btn-primary">Adicionar</button>
</form>
{% endblock %}
在后端,我遵循:
app.py
@app.route('/patterns',methods = ['POST', 'GET'])
def default_patterns():
if request.method == 'POST':
default_value = ''
pattern_name = request.values.get('pattern_name_input', default_value)
pattern_head = request.values.get('pattern_head_input', default_value)
pattern_middle = request.values.get('pattern_middle_input', default_value)
pattern_tail = request.values.get('pattern_tail_input', default_value)
P_Find.set_new_pattern(pattern_name, pattern_head, pattern_middle, pattern_tail)
default_params = P_Find.get_default_params()
flash("Novo padrão adicionado","info")
return render_template('default_patterns.html', zippado=default_params)
我以这种方式获得了正确的值,但是问题是当我在表单的内容中放入space
字符时,我只收到space
之前的文本的第一部分。如何以正确的方式获取文本?
答案 0 :(得分:0)
问题在于呈现此值的方式,以前我有过:
{% for n, h, m, t in zippado %}
<fieldset>
<legend>{{ n }}</legend>
<input type="text" value={{ h }} readonly>
<input type="text" value={{ m }} readonly>
<input type="text" value={{ t }} readonly><br><br>
</fieldset>
{% endfor %}
我只是将'
放在值字段中并工作了
{% for n, h, m, t in zippado %}
<fieldset>
<legend>{{ n }}</legend>
<input type="text" value='{{ h }}' readonly>
<input type="text" value='{{ m }}' readonly>
<input type="text" value='{{ t }}' readonly><br><br>
</fieldset>
{% endfor %}