0
Hello I am trying to do a simple procedure, but I stopped at the problem below. I have the simple goal of passing a parameter and filtering a list of associates. I have the following codes:
Python
@app.route("/listafiltrada/<int:doc>", methods=['GET', 'POST'])
def listafiltrada(doc):
associados = Associado.query.filter_by(Documento=doc)
return render_template("listafiltrada.html", associado=associados)
This is the code that sends the parameter:
<form action="{{ url_for('listafiltrada') }}" method="GET">
Nome<input type="text" id="doc" name="doc">
<input type="submit" value="FILTRAR">
<br>
</form>
And this is the code you get:
<body>
<h1>Lista Filtrada</h1>
<form action="" method="POST">
<table border="4">
<tr>
<td>IdAssociado</td>
<td>Nome</td>
<td>Telefone</td>
<td>Documento</td>
<td>E-mail</td>
<td>Excluir</td>
<td>Atualizar</td>
</tr>
{% for i in associado %}
<tr>
<td>{{ i.IdAssociado }}</td>
<td>{{ i.Nome }}</td>
<td>{{ i.Telefone }}</td>
<td>{{ i.Documento }}</td>
<td>{{ i.Email }}</td>
<td><a href="/excluir/{{ i.IdAssociado }}">X</a></td>
<td><a href="/atualizar/{{ i.IdAssociado }}">Atualizar</a></td>
</tr>
{% endfor %}
</table>
</form>
<a href="/index">Voltar</a>
</body>
But when executing the procedure the following error appears: werkzeug.routing.Builderror: Could not build url for 'filtered listed' endpoint. Did you Forget to specify values ['doc']?
How do we fix this? Thank you
Hello jsbueno, thank you for your reply. It worked well, only had to change the code "doc = request.get("doc")" to "doc = request.args.get('doc')", because the system had returned me the following error: "Attributeerror: 'Request' Object has no attribute 'get'". Thank you very much!
– Pedro Lor Orlando
This - I tidied up in the reply - I thought one thing and typed another - is that the
get
is used in dictionaries, and.GET
is used in the request object of some other frameworks (instead of "args")– jsbueno