Executing a python script from web page
- Posts: 9
- Joined: Tue May 02, 2017 4:31 pm
- Posts: 1098
- Joined: Tue Jan 19, 2016 2:17 pm
Because that wouldn't be executing the scripts from a web page!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.
I'm no expert on this but found this with various suggestions http://stackoverflow.com/questions/448837/how-do-i-create-a-webpage-with-buttons-that-invoke-various-python-scripts-on-the
stackoverflow.com is always a good place to start.
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
(I know it's not the best practice, but it's a $35 hobby project; I'm not too concerned about security.)
- Posts: 8
- Joined: Mon Apr 22, 2013 7:14 pm
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,
- Posts: 1141
- Joined: Wed Jun 12, 2013 12:41 pm
- Location: Stuttgart Germany