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 Overflow
๐ŸŒ
TMS Developer Blog
tms-dev-blog.com โ€บ home โ€บ python backend with javascript frontend: how to
Python backend with JavaScript frontend: how to - TMS Developer Blog
August 6, 2024 - In this tutorial we will learn how to build a Python backend and have a JavaScript frontend connect to it. A full basic example.
Discussions

How 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
This is for my mini project which is evaluated..basically i need a GUI to show double hashing implementation. I used html and css to create my front end but i am not able to connect my back end to ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
javascript - Integrating Python back-end with HTML/CSS/JS User Interface for desktop applications? - Stack Overflow
How could I or would it be appropriate to integrate Python code with HTML/CSS/JS as the user interface in creating desktop applications. A simple example; if I wanted to created a function with Pyt... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to run a Python script like a backend in HTML - Stack Overflow
Is it possible to run a python script from html code without any limitations I am trying to create a combo of a webpage and a python script which lets users to scrape a particular website/s and dis... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Bridging a Python back-end and JavaScript front-end - Stack Overflow
I'm currently working on a project that involves parsing through a user-supplied file, doing computations with that data, and visualizing the results using graphing utilities. Right now, I'm stuck ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Reddit
reddit.com โ€บ r/learnprogramming โ€บ how do u connect front end (html) with back end ( python code)
r/learnprogramming on Reddit: How do u connect front end (html) with back end ( python code)
April 13, 2021 -

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

Top answer
1 of 7
6
Ok so like you have two popular alternatives: django and flask. But before you dive deep into python libraries convince yourelf that a large portion of front end talking to backend is a module known as an 'RESTful Application Programming Interface' or API. I promise all of this is way easier than it sounds. An rest api is just a module of code (flask,django,nodejs) that runs perpetually waiting for HTTP get and post requests. Just go through any basic youtube tutorial, there are thousands: and whenever you get stuck search for solutions on stackoverflow, if your problem has not been asked yet post a question yourself; most answers are given within like 6 hours. Sorry I know you know how stackoverflow works :'p Just don't be reluctant to post questions because you are bound to run into problems, a very popular one for example is that when returning a json object as a http response most learners do not add the "Access-Control-Allow-Origin" header which then blocks the client server communication across platforms in python-flask: res.headers.add('Access-Control-Allow-Origin':'*'); Also, an additional recommendation, before you upload your python code to heroku 1.make a 'requirements.txt' file in the directory you want to upload 2.open terminal and run the command 'pip freeze'. You'll get a list of all the libraries you have installed. Copy this list as it is and paste it in requirements.txt (if you're using Linux run the command 'pip freeze>requirements.txt') 3.install gunicorn by running command 'pip install gunicorn' 4.make another textfile name it procfile and put this code fragment in it 'web:gunicon :app' so if your code is in server.py 'web:gunicorn server:app' This is all info you will come across in your learning process anyways just giving a heads up. Happy coding :))
2 of 7
3
Maybe something like Flask? https://flask.palletsprojects.com/en/1.1.x/
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 56179495 โ€บ how-to-connect-my-python-back-end-to-my-html-front-end-to-create-a-gui-for-doubl
How 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
double hash page in html where i need to embed my python code: <html> <head> <link href='style1.css' rel='stylesheet' type='text/css'> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon"> <link rel="icon" href="favicon.ico" type="image/x-icon"> <!--<script src="hash.js"></script>--> <!-- method i tried to embed my code --> <!--<script type="text/javascript"> function runPyScript(input){ var jqXHR = $.ajax({ type: "POST", url: "/double", async: false, data: { mydata: input }}); return jqXHR.responseText;} $('#submitbutton').click(function(){ datatosend = 'this is my matrix'; result
๐ŸŒ
Saashammer
saashammer.com โ€บ blog โ€บ how-to-combine-frontend-and-backend-for-python-web-developers
How to Combine Frontend and Backend (For Python Web Developers) | SaaS Hammer
Django or Flask will treat the built assets as normal assets and do not care where they come from. Django or Flask will add the JS and CSS link to the template to make sure browser can download them. ... When user visits the website, web server process the request, render HTML using Django template or Jinja. ... The browser run Javascript to sprinkle the server-rendered HTML. We can use python-webpack-boilerplate to jump start frontend project bundled by Webpack.
Top answer
1 of 3
2

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
2 of 3
1

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.).

Find elsewhere
๐ŸŒ
Quora
quora.com โ€บ Can-I-use-python-as-a-backend-and-JavaScript-for-front-end-to-make-a-advanced-high-quality-web-development-or-website
Can I use python as a backend and JavaScript for front end to make a advanced high quality web development or website? - Quora
Answer (1 of 3): Yes, its possible. But selecting your technology stack before knowing the intricate details of what โ€œadvanced high quality web development or websiteโ€ is, is kind of like putting the cart before the horse. Most things can be accomplished using this stack.
๐ŸŒ
Quora
quora.com โ€บ How-can-I-integrate-a-Python-backend-into-a-JavaScript-frontend
How to integrate a Python backend into a JavaScript frontend - Quora
Answer (1 of 7): First make sure your JavaScript in the front end has a way of making XHR/AJAX requests. Axios is one option but there are others. For example XHR requests are built into front end frameworks like Angular. You can send requests a lot of ways but typically JSON headers and format a...
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ pyscript-python-front-end-framework
How to Use PyScript โ€“ A Python Frontend Framework
May 12, 2025 - But thankfully, Python developers ... year, during the PyCon 2022 conference, Anaconda announced a framework named PyScript that allows you to use Python on the web using standard HTML......
Top answer
1 of 2
10

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.

2 of 2
6

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 :-))

๐ŸŒ
Quora
quora.com โ€บ How-can-I-link-my-front-end-code-HTML-with-a-backend-Python-most
How to link my front-end code (HTML) with a backend (Python most) - Quora
You will need to call those python backend endpoints from your frontend application using javascript. The most basic idea of linking is to get data from the backend and populate it or send POST data to server.
๐ŸŒ
GitHub
github.com โ€บ 0PrashantYadav0 โ€บ Python-Javascript
GitHub - 0PrashantYadav0/Python-Javascript: This repo is base of how to connect python backend and javascript frontend. ยท GitHub
Welcome to this project! This readme will guide you through the basic steps to connect a Python backend to a JavaScript frontend using API calls.
Author ย  0PrashantYadav0
๐ŸŒ
Full Stack Python
fullstackpython.com โ€บ javascript.html
JavaScript - Full Stack Python
Understanding Data Types in JavaScript examines JavaScript's dynamic data type model and how it manifests in the way numbers, string, Booleans and arrays are used. Create a simple HTML file with basic elements in it. Use the python -m ...
๐ŸŒ
Quora
quora.com โ€บ How-do-I-use-python-as-back-end-for-HTML-for-processing-queries-and-returning-data-to-HTML-for-updating-the-information
How to use python as back-end for HTML for processing queries and returning data to HTML for updating the information - Quora
Answer (1 of 4): What youโ€™re asking here essentially boils down to โ€œHow do I make a web application in Python?โ€ There are lots of ways to do this, but probably the simplest is by using Flask, a basic framework that provides just enough to get started, without overwhelming you with so much stuff ...
๐ŸŒ
Oneclickitsolution
oneclickitsolution.com โ€บ home โ€บ solutions
Run Python in HTML Using PyScript | 2026 Step-by-Step Guide
February 9, 2026 - Learn how to run Python in HTML using PyScript. Updated 2026 tutorial with examples, libraries, charts, and SEO best practices.
๐ŸŒ
LinkedIn
linkedin.com โ€บ pulse โ€บ how-can-python-integrated-html-css-basic-web-brecht-corbeel-yooae
How Can Python Be Integrated with HTML and CSS for Basic Web Development?
July 1, 2024 - Bridging these technologies involves understanding how Pythonโ€™s backend operations can influence and be reflected in the frontend user interface. This includes employing AJAX (Asynchronous JavaScript and XML) for asynchronous web page updates, a technique that enhances user experience by allowing the webpage to update content without a full reload.
๐ŸŒ
Quora
quora.com โ€บ How-do-you-use-Python-as-a-back-end-language-for-an-HTML-site
How to use Python as a back-end language for an HTML site - Quora
Answer (1 of 5): The simplest way would be to use Bottle or its refined alternative Flask. Since you already know that front end will be in HTML and back end in Python, the only thing missing here is the glue called middleware.
๐ŸŒ
Andrew Montalenti
amontalenti.com โ€บ 2012 โ€บ 06 โ€บ 14 โ€บ web-app
Build a web app fast: Python, HTML & JavaScript resources
December 5, 2024 - Youโ€™ll love these Python, HTML/CSS, and JavaScript resources. Iโ€™ve been sharing these documents with friends who ask me, โ€œI want to start programming and build a web app, where do I start?โ€. These resources have also been useful to existing programmers who know C, C++ or Java, but who want to embrace dynamic and web-based programming. ... Python is the core backend and web programming language used at Parse.ly.
๐ŸŒ
Real Python
realpython.com โ€บ tutorials โ€บ front-end
Frontend Web Development Tutorials โ€“ Real Python
Complete web applications combine Python backends with modern frontend technologies. Build user interfaces with HTML, CSS, and JavaScript that communicate with your Flask or Django APIs.