#๐Ÿ”’ How to use python script on HTML Without flask, cgi, django and php ?

64 messages ยท Page 1 of 1 (latest)

onyx flume
#

Hello,

I wanted to use a python script trough a button on a html website but I can't find any solution. It's for a project for school. I've found (I think) a solution but it doesn't work... Basically, my script should turn on a matrix led and show the date when we cllick on the button.

Website button: https://medium.com/@brajagopal.tripathi/how-to-run-a-python-script-from-an-html-button-17058bf5dbe5

Medium

To run a Python script from an HTML button, you can use the following steps:

deft stagBOT
#

@onyx flume

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

supple whale
#

hmm

#

that article looks like nonsense

#

There's no subprocess.run in javascript

supple whale
#

you'll need some sort of server running to be able to send a request from your website to do something from Python

onyx flume
#

basically, the project is that we connect to another pi that is used like a nas where the html, css and python are on, and the principal pi has a matrix led and gonna run all of it

#

sorry my english is kinda bad haha

#

should I setup a php file ?

#

but even that, i don't know how to do it hahah

supple whale
#

How do you plan for the two pis to communicate with each other?

onyx flume
#

wi-fi

#

just access to a nas

#

that's all

#

simply go on the nas and launch the website

#

i mean the html

spare flame
#

what is like the TLDR for this ??

#

i am confused where the matrix is connected to , how it is being controlled, what do the 2 pis are doing here

onyx flume
#

on the gpio of the principal pi, connected trough a python script. The second pi is simply a nas

spare flame
onyx flume
#

there is a button on the html that gonna launch the python script to show the date or hour on the matrix

#

we wanted to add an option where the user could tape something and the matrix would show it but it's look kinda hard for us XD

spare flame
#

so far i have understood the following -

you have 2 raspberry pis , one raspberry pi has a LED matrix attached to it , another raspberry pi is a NAS

and you want to press button somewhere and want to show time on LED matrix

thats all i know till now

onyx flume
#

there are the files

#

if you see there is "add to favorites" button

#

we wanted that when we click on it, it would launch the python script

spare flame
#

ok

can you answer the questions i asked please ?

onyx flume
#

hmm

#

we can access to the website if we put the ip on the browser

spare flame
#

if the questions are not clear , ill rephrase
you have 2 raspberry pis , lets call the (LED pi and NAS pi)

so,

  • where is this HTML file and python file located ?? in the NAS pi or LED pi ??

  • HOW is the user going to use this HTML file ??? you said that if we put ip in the browser , we see the HTML , so its most likely being hosted by some webapp , so my question is , who is hosting that webapp ? like , do you have a flask app or django app running on your pi? or are you just using the "live server" extension or smth similar in vscode ?

  • how are the 2 pis connected to each other ?? do both of them connect to a central wifi router ?

#

also , what is the IP address that you type in ?

onyx flume
#

-HTML files are located on the nas pis

-asked the mate who did it, he's says that you can just enter the ip on the browser and thats it. no even xampp or equivalent. No flask or django app running on led or nas pi. Not even installed.

-same wifi router

spare flame
#

what is the URL you enter in your browser to see the HTML ? show us the full URL

onyx flume
#

just the ip

spare flame
#

where do you type in this IP address ?? on a computer / laptop / or in the LED pi ?

onyx flume
#

now ? on my laptop

#

my led pi is off

spare flame
#

is the laptop connected to the same wifi router ?

onyx flume
#

i have othe class now

spare flame
# onyx flume yup

and only by typing in that address , you see the HTML file right ? like , you dont have to click somewhere and open it

onyx flume
#

right

#

the adress send me to the html

spare flame
#

meaning , if you typed in the IP address in an incognito tab , it would directly open the HTML file , you wont have to click anything , right ?

onyx flume
#

incognito reconized it

spare flame
#

that makes no sense

#

can you speak clearly ?

#

does the webpage show or not ?

onyx flume
#

yeah

spare flame
#

ok , so there is something that is "hosting" the file , we need access to that

#

you dont just "go" to an IP address and you see some HTML file

onyx flume
#

don't know

#

asking the mate that does that

spare flame
#

what you can do is , make a webserver on the LED pi , that will turn on the LED whenever a request comes in

and in the HTML that you use , whenever the button is clicked, make a request to that API on LED pi

onyx flume
#

gonna try that

#

he used apache... XD

#

so we can run a php file ?!

deft stagBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.