How do I connect front end HTML/JQuery to backend Python -
i have web page written in html, , actions completed using jquery. html code below doesn't use of jquery, figured i'd mention since may need put ajax in there.
here "front end"
index.html
<!doctype html> <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script> <script src="javascript.js"></script> <html> <div id="liveoutputtitle"> <h1><span>live output</span></title> </div> <div id="liveoutput"> value 1 python: <input type="text" name="value1" id="value1" value="0"><br> value 2 python: <input type="text" name="value2" id="value2" value="0"><br> value 3 python: <input type="text" name="value3" id="value3" value="0"><br> </div>
i have jquery file, doesn't affect i've put in html file. here's reference file.
jquery.js
$(document).ready(function(){ //logic other functionality of site //i'm assuming ajax goes here });
my end goal have python program pulls values somewhere, , i'd have values shown in input fields.
my python "server side" code. below:
serverside.py
#!/usr/bin/env python def getvalueone(): //gets value wherever valueone = 1 def getvaluetwo(): //gets value wherever valuetwo = 2 def getvaluethree(): //gets value wherever valuethree = 3
how values here, in python, show these values change, respective input values in html?
i've tried figuring out using tutorials on ajax, haven't managed logic together. i've read through this, this, , this, i'm still not sure how connect logic. appreciated.
edit 1
i'm sure should have mentioned frame work want use (assuming have use framework). i'm not sure, i've read lot flask, , if had randomly choose one, use flask.
you try build api in backend, able jquery specified urls , data response (usually json).
so if define url as: http://www.example.com/users
return json list of users.
that url should associated view in backend:
import json def getusers(): users = db.get_users() # example return json.dumps(users)
and json can use in jquery render in front end.
Comments
Post a Comment