Post your image with FileReader API (readAsDataURL).
Write your image into a file with python (beware of base64 encoding)
Then return a Json with Flask (either error or success)
Display image or error message depending on result from server.
I hope this is enough information. Happy coding
Answer from Domenik Reitzner on Stack OverflowHow to connect my python back end to my HTML front end to create a GUI for Double hashing ? Any other means to create a GUI? - Stack Overflow
javascript - Integrating Python back-end with HTML/CSS/JS User Interface for desktop applications? - Stack Overflow
How to run a Python script like a backend in HTML - Stack Overflow
Bridging a Python back-end and JavaScript front-end - Stack Overflow
Videos
Can u help me guys , So i have an html file that has all the front end and another folder that has python codes( back end ) and i want to connect them together then deploy them to heroku . Do u guys know how do i do it?? Please i really need this for a school project
You're best option is to look at Flask (Almost no learning curve) as a backend and you can continue using HTML/CSS/JS as frontend.
However to create a desktop application you will need to integrate (Your frontend) with tools like electron.
Yes you can. You need to choose framework of python. like Django etc. Then you can make own desktop application as you can.
Try using streamlit (https://streamlit.io)
code (app.py)
# import module
import streamlit as st
import requests
# Title
st.title("Running python from browser")
# Taking user input
user_input = st.text_input("Enter site to scrape")
# your script
if user_input:
r = requests.get(user_input)
st.write(r.status_code)
To deploy simply run
streamlit run app.py
There's a library called Brython (https://brython.info/), it can help you somewhat, but of course consider that there are limitations.
Here's the example of how to send request to HTTP site:
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript"
src="https://cdn.jsdelivr.net/npm/[email protected]/brython.min.js">
</script>
<script type="text/javascript"
src="https://cdn.jsdelivr.net/npm/[email protected]/brython_stdlib.js">
</script>
</head>
<body onload="brython()">
<script type="text/python">
from browser import ajax
from browser import document
query = ''
url = 'http://www.http2demo.io/'
def get_request(url, q):
req = ajax.ajax()
req.bind('complete', on_complete)
req.open('GET', url+'?'+q, True)
req.set_header('content-type', 'application/x-www-form-urlencoded')
req.send()
def on_complete(r):
if r.status==200 or r.status==0:
document <= r.text
else:
document <= "error: " + r.text
get_request(url, query)
</script>
</body>
</html>
The better approach would be to create microservice, which would consist of front-end (user inputs URL to parse) and back-end (python logic - requests, etc.).
Apache is a web server, flask is a web framework in python, websockets are a protocol, and cgi is something totally different, and none of them help you on the front end.
You could deploy a simple backend in flask or django or pylons or any other python web framework. I like django, but it may be a little heavy for your purpose, flask is a bit more lightweight. You deploy them to a server with a web server installed and use something like apache to distribute.
Then you need a front end and a way of delivering your front end. Flask / Django are both fully capable of doing so in conjunction with a web server, or you could use a static file server like Amazon S3.
On your front end, you need to load D3 and probably some kind of utility like jQuery to load and parse your data from the back end, then use D3 however you like to present it on screen.
Flask is easy to get up and running and is Python based. It works well with REST APIs and data sent by JSON (or JSON API).
This is one solution with which I have some experience and which seems to work well and is not hard to get up and running (and natural to work with Python). I can't tell you whether it is the best solution for your needs, but it should work.
If you are overwhelmed and don't know where to start, you can pick one of the options and google search for a tutorial. With a decent tutorial, you should have an example up and running by the end of the tutorial, and then you will know if you are comfortable working with it and have an idea whether it will meet your needs.
Then you could do a proof-of-concept; make a small app that just handles one small part (the one you are most concerned about handling, perhaps) and write something which will do it.
By then, you can be pretty sure you have a good tool for the purpose (unless you were convinced otherwise by the proof-of-concept -- in which case, try again with another option :-))