2

I have a web page that is written in HTML, and the actions are completed using JQuery. The html code below doesn't use any of the JQuery, but I figured I'd mention that since I may need to put some AJAX in there.

Here is the "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 From Python: <input type="text" name="Value1" id="Value1" value="0"><br>

Value 2 From Python: <input type="text" name="Value2" id="Value2" value="0"><br>

Value 3 From Python: <input type="text" name="Value3" id="Value3" value="0"><br>

</div>

I have a JQuery file, that doesn't affect anything that i've put in the html file. But here's a reference to that file.

jquery.js

$(document).ready(function(){
    //logic for other functionality of the site

    //I'm assuming some AJAX goes here
});

My end goal is to have a python program that pulls values from somewhere, and I'd like to have those values shown in the input fields.

My python "server side" code. does something like below:

serverSide.py

#!/usr/bin/env python

def getValueOne():
    //gets the value from wherever
    valueOne = 1

def getValueTwo():
    //gets the value from wherever      
    valueTwo = 2

def getValueThree():
    //gets the value from wherever
    valueThree = 3

How do I get the values here, in the python, to show as these values change, to the respective input values in the HTML?

I've tried figuring that out using some tutorials on AJAX, but I haven't managed to get the logic completely together. I've read through this, this, and this, but I'm still not exactly sure how to connect this logic. Any help is appreciated.

EDIT 1

I'm sure someone will say that I should have mentioned what frame work I want to use (assuming you have to use a framework). I'm not sure, but I've read a lot about flask, and if I had to randomly choose one, I would use flask.

1 Answer 1

2

You could try to build an API in your backend, then you will be able to get from JQuery to specified urls and get some data as response (usually json).

So if you define an url as: http://www.example.com/users it will return a json with the list of users.

That url Should be associated to a View in your backend:

import json
def getUsers():
    users = db.get_users() # just an example
    return json.dumps(users)

And as a json you can use it in JQuery to render it in front end.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.