element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Dev Tools
  • Products
  • More
Dev Tools
Forum Run python script for HTML web page
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Dev Tools to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 9 replies
  • Subscribers 80 subscribers
  • Views 2223 views
  • Users 0 members are here
Related

Run python script for HTML web page

Former Member
Former Member over 10 years ago

Is there a way to run python script for html webpage? it's very important. i have a python script works fine in my raspberry Pi but i want to work with my home page,

how can i do that?

  • Sign in to reply
  • Cancel
Parents
  • Former Member
    Former Member over 10 years ago

    Please i want to know what's wrong in this html code to execute my python script via internet.

     

    <html>

    <head>

    <?php

    if (isset($_POST['LightON']))

    {

    exec("sudo python /var/www/lighton.py");

    }

    if (isset($_POST['LightOFF']))

    {

    exec("sudo python /var/www/lightoff.py");

    }

    ?>

     

    <form method="post">

    <button class="btn" name="LightON">Light ON</button> 

    <button class="btn" name="LightOFF">Light OFF</button><br><br>

        <br><br><br><br>

    </form>

    </html>

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • clem57
    clem57 over 10 years ago in reply to Former Member

    <?php

    if (isset($_POST['LightON']))

    {

    exec("sudo python /var/www/lighton.py");

    }

    if (isset($_POST['LightOFF']))

    {

    exec("sudo python /var/www/lightoff.py");

    }

    ?>

    This has several issues:

    1. It looks to be PHP. Do you have this on your pi?
    2. Usually PHP is server side code and not visible on the client side or in the browser.
    3. Do you really really want to allow SUDO from the web? This is a hackers dream to see and exploit! A better although a bit complicated way would be to change a file like light.txt to on/off and let the python script read it in the background to perform the task.

     

    If you want a simpler way to control the light take a look at REST API in http://lmgtfy.com/?q=raspberry+pi+rest+server

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • clem57
    clem57 over 10 years ago in reply to clem57

    http://www.instructables.com/id/Building-a-Web-Enabled-Door-Lock-using-Rest-API-an/

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 10 years ago in reply to clem57

    Thank you very much, i do have the python code, on my pi, i really do not care much about the security now, but i want to find a way to be able to control these 2 python code over the internet or intranet.

     

    if you could please help me out i would appreciated

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • Former Member
    Former Member over 10 years ago in reply to clem57

    Thank you very much, i do have the python code, on my pi, i really do not care much about the security now, but i want to find a way to be able to control these 2 python code over the internet or intranet.

     

    if you could please help me out i would appreciated

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube