I am a beginner in python. For practice reasons I want to learn how to upload a python code to a website.
I have a domain and web hosting service, however I’m really confused about how to integrate my code with a
web page on my website.
(I have a decent bit of knowledge with Tkinter)
Can anybody show me how to upload this simple function to my website?:
There are two entries on the interface for the user to enter two numbers. On pressing a button a new
window(web page) with the answer displayed.
Thank you.
The Basics
Here is a very simple server-side Python script. To use it, put it in your
cgi-binfolder on your server. (It can later be configured to run elsewhere, butcgi-binusually works out of the box.) Then change the permissions on the file viachmodor some Gui control. You need to allow anyone to execute it, so755will do. Then navigate to http://domain.tld/cgi-bin/myscript.py.If that works you can move on to running more complicated scripts, using frameworks (like web.py), and responding to forms.
Form Data
To answer the actual question, we need a page with a form. I made this from a template I use and added a form with a singe input field.
Notice it’s pointing to our
test.pyscript. That needs to be updated too so it understands ourmystuffform element. We throw in some error handling and import our cgi modules. Theexceptpart is lazily done, but since you won’t use that part of the code, I don’t think it’s that important.You should be able to go to your web-page and enter 7 in the field, which will result in a page containing…
Hope that helps.