Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6920863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:12:10+00:00 2026-05-27T10:12:10+00:00

I am a beginner in python. For practice reasons I want to learn how

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:12:11+00:00Added an answer on May 27, 2026 at 10:12 am

    The Basics

    Here is a very simple server-side Python script. To use it, put it in your cgi-bin folder on your server. (It can later be configured to run elsewhere, but cgi-bin usually works out of the box.) Then change the permissions on the file via chmod or some Gui control. You need to allow anyone to execute it, so 755 will do. Then navigate to http://domain.tld/cgi-bin/myscript.py.

    #!/usr/bin/python
    
    print "Content-type: text/html"
    print
    print "<pre>"
    import os, sys
    from cgi import escape
    print "<strong>Python %s</strong>" % sys.version
    keys = os.environ.keys()
    keys.sort()
    for k in keys:
        print "%s\t%s" % (escape(k), escape(os.environ[k]))
    print "</pre>"
    

    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.

    <!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>Webpage</title>
      <meta name="description" content="html5 webpage">
      <meta name="author" content="">
      <!--[if lt IE 9]>
      <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
      <![endif]-->
    </head>
    <body>
        <form action="/cgi-bin/test.py">
        <input name="mystuff" width="500px" />
        <input type="submit" value="Do" />
        </form>
    </body>
    </html>
    

    Notice it’s pointing to our test.py script. That needs to be updated too so it understands our mystuff form element. We throw in some error handling and import our cgi modules. The except part is lazily done, but since you won’t use that part of the code, I don’t think it’s that important.

    print "Content-type: text/html"
    print
    print "<pre>"
    
    import os, sys
    import cgi, cgitb
    cgitb.enable()
    
    form = cgi.FieldStorage()
    
    try: 
        num = int(form['mystuff'].value)
        print 'The number %d to the 13th power is %d.' % (num, num**13)
    except Exception: 
        print 'What am I suposed to do with that?  This is what you call an "err
    or message".  Try a number instead'
    
    print "</pre>"
    

    You should be able to go to your web-page and enter 7 in the field, which will result in a page containing…

    The number 7 to the 13th power is 96889010407.

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am still a python beginner. As a practice project I want to code
beginner to python here. I have 2 nested lists that I want to merge:
I'm a beginner using python 3.2 and i have a book whos code is
As part of the last assignment in a beginner python programing class, I have
I am a beginner of python and have a question, very confusing for me.
A beginner's Python question: I have a string with x number of sentences. How
I am a beginner with Python and trying few programs. I have something like
I'm still a beginner to Python, so I thought I could as well learn
I am just a beginner in python. I have document score= {1:0.98876, 8:0.12245, 13:0.57689}
I'm an absolute beginner using IDLE (Python 2.6.4) to learn the basics. I recently

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.