![]() |
ubuntu.com - launchpad.net - ubuntu help
|
|
|||||||
Ubuntu 9.10 is out!!!
When downloading Ubuntu 9.10 please consider using bittorrent to get your copy of Ubuntu. The Ubuntu Developers Summit for Lucid Lynx will be held the week of 16-Nov-2009 till 20-Nov-2009 in Dallas, TX USA. Visit the the Ubuntu wiki for more information about UDS and how to participate remotely. |
|
Programming Talk This forum is for all programming questions. The questions do not have to be directly related to Ubuntu and any programming language is allowed. |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Day Old Decaf
![]() Join Date: Jun 2006
Location: CT, USA
Beans: 5,268
Ubuntu 6.10 Edgy
|
Hello Web - 2 simple web apps in python (3 lines and 35 lines)
Someone complained that Python web app tutorials are harder than PHP. So I created these two simple python apps to help you started.
I assume you have cgi-enabled directory. UPDATE 1: Find your python first. In terminal, type 'which python'. Then change first line of following scripts according where your python is: /usr/bin/python or /usr/local/bin/python or whatever you have. (end update1) Simplest one (3 lines): place it in CGI-enabled directory, make executable by web user (or anybody, or all): Code:
#!/usr/bin/python import cgi cgi.test() More complicated (35 lines including 13 lines of HTML template), but still simple: Code:
#!/usr/bin/python
import cgi
import cgitb; cgitb.enable()
import os
##---CONSTANTS -------
BGCOLOR = '#f0f0f0'
##---TEMPLATES ----------------------------------------------------
HTML = """content-type: text/html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>%(TITLE)s</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head><body bgcolor="%(COLOR)s"><h1>%(TITLE)s</h1>
<h2>Hello %(NAME)s</h2>
<hr /><h2> Who are you?</h2>
<form action="%(SCRIPT_NAME)s" method="POST" enctype="multipart/form-data">
<input name="person_name" type="text" size="40"><br />
<input name="submit" type="submit" value="Try">
</form>
</body></html>"""
def main():
FORM = cgi.FieldStorage()
person = FORM.getfirst('person_name')
if not person:
person = '(Nobody yet)'
next_script = os.environ['SCRIPT_NAME'] # name of this script: it submits to self
print HTML % dict(TITLE='Hello Web!', NAME=person,
SCRIPT_NAME=next_script, COLOR=BGCOLOR)
# idiomatic start of the main() program
if __name__ == '__main__': main()
Good luck! Last edited by pmasiar; January 6th, 2007 at 12:55 AM.. |
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|