The simplest way is:
```
cpf = request.params["cpf"]
rows = request.dbsession.query(Paciente).filter(cpf=cpf),all()
```
O codigo no formato acima não executou, apresentou erro, mas foi de grande
valia, muito obrigado). Fiz uma pequena alteração e deu certo.
Funcionou assim:
cpf = request.params["cpf"]
rows = request.dbsession.query(Paciente).filter(Paciente.cpf==cpf).all()
Você deve notado no enuciado do assunto, que além da consulta, tenho o
problema do resultado ser publicado em outra pagina.
codigo da pagina de consulta
# templates/pac_recepx.jinja2
<div class="form">
<div class="row g-2 mt-3">
<h3><span class="font-semi-bold">Consultar cadastro do
paciente</span></h3>
</div>
<form class="form-inline my-2 my-lg-0"
action="http://localhost:6543/queryx" method="GET">
<label for="cpf">Digite o CPF (11 números)</label>
<input class="form-control mr-sm-2" type="text" id="cpf"
name="cpf" required maxlength="11" value=''>
<button class="btn btn-outline-success my-2 my-sm-0"
type="submit">Consultar</button>
</form>
</div>
O resultado esta indo para ...
action="http://localhost:6543/queryx
Como faço para levar esse resultado para dentro da mesma da pagina que
esta fazendo a consulta (templates/pac_recepx.jinja2 ), ou seja, coloca-lo
abaixo da consulta?
Desde já agradeço seu apoio.
Oberdan Costa
Em quarta-feira, 22 de novembro de 2023 às 20:33:04 UTC-3, Mike Orr
escreveu:
> The simplest way is:
>
> ```
> cpf = request.params["cpf"]
> rows = request.dbsession.query(Paciente).filter(cpf=cpf),all()
> ```
>
> This doesn't do any validation or graceful error reporting on the
> input value, so you may want to use Colander or FormEncode for that. I
> use FormEncode. Otherwise invalid input may lead to a Python exception
> and an Internal Server Error for the user, and 'cpf' will be a string
> even if the database field is integer.
>
> On Wed, Nov 22, 2023 at 1:34 PM Oberdan Santos <[email protected]> wrote:
> >
> > Hello!!! I'm trying to make the code below work as follows.
> > When filling out the data entry, click on the query button.
> >
> > # template/pac_recepx. jinja2
> >
> > <div class="form">
> > <div class="row g-2 mt-3">
> > <h3><span class="font-semi-bold">Consultar cadastro do
> paciente</span></h3>
> > </div>
> > <form class="form-inline my-2 my-lg-0" action="
> http://localhost:6543/queryx" method="GET">
> > <label for="cpf">Digite o CPF (11 números)</label>
> > <input class="form-control mr-sm-2" type="text" id="cpf" name="cpf"
> required maxlength="11" value=''>
> > <button class="btn btn-outline-success my-2 my-sm-0"
> type="submit">Consultar</button>
> > </form>
> > </div>
> >
> > In this view, using the code below, it shows all registered patients.
> >
> > @view_config(route_name='queryp',
> renderer='piprdc:templates/pac_query.jinja2')
> > def queryp(request):
> > rows = request.dbsession.query(Paciente).all()
> > pacientes=[]
> > for row in rows:
> > pacientes.append({"id":row.id, "name":row.name, "idade":row.idade,
> "data_nascimento":row.data_nascimento, "sexo":row.sexo,
> > "raca":row.raca, "fone":row.fone, "endereco":row.endereco,
> "cpf":row.cpf, "cns":row.cns})
> > return{'pacientes':pacientes}
> >
> > The question is, how do I make it show only the patient I requested the
> appointment with? I've looked at a lot of content, but I can't create a
> logic for it to take the past information (cpf), compare it and display it.
> >
> > Every help is welcome.
> >
> > Oberdan costa
> >
> >
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "pylons-discuss" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to [email protected].
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/pylons-discuss/25b36bc3-0c71-4587-b79f-dfb26e83e7f7n%40googlegroups.com
> .
>
>
>
> --
> Mike Orr <[email protected]>
>
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pylons-discuss/10bef9da-a8cc-4553-b625-614128268bccn%40googlegroups.com.