Jump to content

using python


Recommended Posts

Hey, everyone. This probably makes me look stupid, but I just don't get how to use python in pages. I get that you make the file in the cgi-bin folder, and add the shebang and header type, but then how do you make this run when you go to a certain page? For example, if you go to eap17.heliohost.org/myprog I want it to run the python script. how do I do that?

Link to comment
Share on other sites

Guest Geoff
Hey, everyone. This probably makes me look stupid, but I just don't get how to use python in pages. I get that you make the file in the cgi-bin folder, and add the shebang and header type, but then how do you make this run when you go to a certain page? For example, if you go to eap17.heliohost.org/myprog I want it to run the python script. how do I do that?

 

 

If you want to include a dynamic page anywhere in your site, you are probably better off using php. However there are two ways to run the python script from another URL. You can also just run it directly.

 

  1. You can go to http://your-url.heliohost.org/cgi-bin/your-python-file.py
  2. You can create an ".htaccess" file in your public_html folder, or edit the one that you already have in their, and add the following lines:

    Options +ExecCGI
    AddHandler cgi-script cgi py

    Then you don't have to put your python files in cgi-bin to run them.

  3. You can Add a rewrite rule to ".htaccess" to rewrite "http://eap17.heliohost.org/myprog" to "http://eap17.heliohost.org/cgi-bin/myprog.py"

    RewriteEngine on
    RewriteRule ^myprog$ \/cgi-bin\/myprog.py

Link to comment
Share on other sites

Ok. Thanks. I'll try some of it. =)

 

I just tried it! It all works great! One thing I forgot to do was set the permissions correctly. Silly me. Thank you so much for the help! I did the rewrite rule and everything. If you want to see my (splendid) piece of python testing, you can go to eap17.heliohost.org/cgi-bin/testprog.py or eap17.heliohost.org/myprog. Thanks so much, again! I'm learning python over the summer, and I want to incorperate it into everything I do. ^_^

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...