0
I have little knowledge in frontend and I’m needing to do the following:
In my Backend I have a function which I run in python and which returns a list according to print.
app = Flask(__name__)
@app.route('/')
def info():
return 'Navegar para os dados'
@app.route('/Teste')
def mensagem():
fd='var_fd'
dt='var_dt'
_engine = sqlalchemy.create_engine("minha_string_de_conexao")
sql = """
select data
from minha_tabela
where codigo like '%{0}%'
and data={1!r}
order by 1 desc;
""".format(fd, dt)
pos = pd.read_sql_query(sql,_engine)
value = str(pos.iloc[0:]['data'].tolist())
return str(value)
if __name__ == '__main__':
app.run()
<div class="col-md-12" align="right" style="font-size:12px;color:black;margin-left:10ox;margin-bottom:15px;">
<select class="form-control" style="width:120px">
<option selected value="">hh:mm:ss</option>
</div>
I need the feedback of that data to be populated in the combobox. I believe that with jquery is a good option, however, I am not able to realize this demand.
As I mentioned initially, I don’t have much knowledge in front. Grateful!
Could someone help me?
Thank you very much for your return. I ended up with a question. At what point does AJAX call the function that is in Python? I must adapt the code you sent me?
– LePy
Here:
$.get("http://127.0.0.1/Teste", function(data){
, the first information between quotes is the URL from which the return of the back end will come, ie.http://127.0.0.1/Teste
.– Sam
I don’t understand Phyton, but in the file where is generated the array that you showed in print, you should return this array to AJAX... In PHP it would be a
echo
.– Sam
Since AJAX is an HTTP request, it is as if you made a file in Phyton that prints on the screen only this array, and AJAX will pull it in string form.
– Sam
Perfect Sam. From what I understand, the step you explained to me "picks up" the URL data that represents the return of the back end. However, for this URL to be generated, I need to call the function in Python which in this case is the def message().
– LePy
That. Basically you should generate a return for AJAX, something that generates a string. I think in Phyton it would be a kind of
print()
.– Sam
From what I see, the function of your Phyton has a Return... you should print this return so that AJAX receives it.
– Sam
Try to mark in the answer of your questions that solved the question. I was looking at your question history and saw that none was finished with . Users' effort to answer questions is rewarded when you score the best answer or vote positive on the ones you found useful. Abs!
– Sam