jebukaty
Posts: 9
Joined: Tue May 02, 2017 4:31 pm

Executing a python script from web page

Thu May 18, 2017 9:12 pm

Hi, I was wondering if I could execute a python script from a web page. I have a adafruit motor hat on my pi that I use to control motors. And I use python to write the script for the motors. If someone could point me in the right direction to be able to execute this script from a web page that would be great, thanks.

alphanumeric
Posts: 1177
Joined: Tue Jan 19, 2016 2:17 pm
Location: Sydney, Nova Scotia, Canada

Re: Executing a python script from web page

Fri May 19, 2017 10:03 am

Why not just clip and past the code into idle (file new) and then save it as a local file? Then run it locally on the Pi.

User avatar
davef21370
Posts: 874
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

Re: Executing a python script from web page

Fri May 19, 2017 4:34 pm

alphanumeric wrote:Why not just clip and past the code into idle (file new) and then save it as a local file? Then run it locally on the Pi.
Because that wouldn't be executing the scripts from a web page!

I'm no expert on this but found this with various suggestions http://stackoverflow.com/questions/4488 ... pts-on-the

stackoverflow.com is always a good place to start.

Dave.
Apple say... Monkey do !!

irab88
Posts: 8
Joined: Mon Apr 22, 2013 7:14 pm

Re: Executing a python script from web page

Fri May 19, 2017 5:14 pm

http://raspberrywebserver.com/cgiscript ... ry-pi.html

This is what I used for my project. While I used text boxes, you can use buttons, check boxes, and more.

Just be sure to set permissions to allow GPIO to be run from a non-root user:

(I wasn't having luck with Jessie, so I used Wheezy for my project)

-$usermod -a -G group user

adding "root", "pi" and "www-data" to the groups "kmem" and "dialout"

However, I was still having issues accessing GPIO, so I had to do the following:

-$sudo nano /etc/rc.local

Code: Select all

...
chmod 777 /dev/mem
chmod 777 /dev/gpiomem
exit 0
(I know it's not the best practice, but it's a $35 hobby project; I'm not too concerned about security.)

ghp
Posts: 1145
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Executing a python script from web page

Fri May 19, 2017 7:09 pm

Hello,
web applications tend to grow. A nice approach to handle this is a python app server as e.g. tornado. See http://www.tornadoweb.org/en/stable/
Extend the sample from the main page with something which has a button and call a class which does something python-style.
As the app server is already in python, there is almost no barrier.
Hope this helps,
Gerhard

Return to “Python”

Who is online

Users browsing this forum: No registered users and 7 guests