Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old March 7th, 2004, 06:49 PM
sonatas sonatas is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 9 sonatas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Exclamation putting .py onto an xhtml

Hi...I've been trying to figure out how to put the program in python onto a webpage.

The program just basically tells you the current time and when you go to the webpage, you're supposed to see the current time.

So how do you apply the python program onto a webpage?

Thanks.

Reply With Quote
  #2  
Old March 7th, 2004, 07:19 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
Do you have any code we could look at. basically all you have to do is give you're program any required headers (Conent-Type) and give it a go. Everything that is printed by Python will end up as part of teh Page.

Note: you will obviously need a server to run the program.

There are alot of threads on this kind of thing and even an article here on devshed that should tell you everything you need to know!

Happy huntingm have fun!

Mark.
__________________
programming language development: www.netytan.com Hula


Reply With Quote
  #3  
Old March 7th, 2004, 07:19 PM
MasterChief MasterChief is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Virginia
Posts: 491 MasterChief User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 47 m 47 sec
Reputation Power: 6
Send a message via AIM to MasterChief Send a message via MSN to MasterChief
Do you have Apache? If so, get http://httpd.apache.org/modules/python-download.cgi

Install mod python (you shouldn't have any problems). Don't forget to restart Apache, afterwards!

Use this as a test, to see if mod python is working:

Code:
#!/usr/bin/env python
print 'Content-Type: text/html\n'
print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">'
print '<html lang="en">'
print ' <head>'
print '  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">'
print '  <link rel="stylesheet" href="/projects/python/python.css" type="text/css" media="screen" title="Python">'
print '  <title>Python on the Web</title>'
print ' </head>'
print ''
print ' <body>'
print '<p>This page is used for testing Python on the Web.</p>'
print '<p><b>Test One (swapcase):</b></p>'
import string
sww = 'Spencer Warren Wilson'
print string.swapcase(sww)
print '<p><b>Test Two (len):</b></p>'
print 'Spencer Warren Wilson = '
print len(sww)
print '<br />Spencer = '
s = 'Spencer'
print len(s)
print '<br />Warren = '
w1 = 'Warren'
print len(w1)
print '<br />Wilson = '
w2 = 'Wilson'
print len(w2)
print '<br /><i>spaces</i> = '
space = '  '
print len(space)
print ' </body>'
print '</html>'


Put

Code:
#!/usr/bin/env python
print 'Content-Type: text/html\n'


at the very top of your script. Use the print statement to print the HTML stuff as a string (put quotes around the stuff).

Tell us how it goes.

Reply With Quote
  #4  
Old March 7th, 2004, 08:38 PM
sonatas sonatas is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 9 sonatas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by MasterChief
Do you have Apache? If so, get http://httpd.apache.org/modules/python-download.cgi

Install mod python (you shouldn't have any problems). Don't forget to restart Apache, afterwards!

Use this as a test, to see if mod python is working:

Code:
#!/usr/bin/env python
print 'Content-Type: text/html\n'
print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">'
print '<html lang="en">'
print ' <head>'
print '  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">'
print '  <link rel="stylesheet" href="/projects/python/python.css" type="text/css" media="screen" title="Python">'
print '  <title>Python on the Web</title>'
print ' </head>'
print ''
print ' <body>'
print '<p>This page is used for testing Python on the Web.</p>'
print '<p><b>Test One (swapcase):</b></p>'
import string
sww = 'Spencer Warren Wilson'
print string.swapcase(sww)
print '<p><b>Test Two (len):</b></p>'
print 'Spencer Warren Wilson = '
print len(sww)
print '<br />Spencer = '
s = 'Spencer'
print len(s)
print '<br />Warren = '
w1 = 'Warren'
print len(w1)
print '<br />Wilson = '
w2 = 'Wilson'
print len(w2)
print '<br /><i>spaces</i> = '
space = '  '
print len(space)
print ' </body>'
print '</html>'


Put

Code:
#!/usr/bin/env python
print 'Content-Type: text/html\n'


at the very top of your script. Use the print statement to print the HTML stuff as a string (put quotes around the stuff).

Tell us how it goes.


I tried putting them in quotes but it turned out funny looking...

this is what it looks like...maybe you can spot the error?

#!/usr/bin/env python
print "Content-Type: text/html\n"
print "<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">"
print "<html xmlns="http://www.w3.org/1999/xhtml">"
print "<head>"
print "<title>Current Time</title>"
print "</head>"
print "<body>"
print "<h1>Current Time</h1>"
print "import time'
print ""Content-type: text/html""
print ""Right now, it is ", time.asctime()"
print "</body>"
print "</html>"


I even tried it as ' '
instead of " "

Reply With Quote
  #5  
Old March 7th, 2004, 08:39 PM
sonatas sonatas is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 9 sonatas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by netytan
Do you have any code we could look at. basically all you have to do is give you're program any required headers (Conent-Type) and give it a go. Everything that is printed by Python will end up as part of teh Page.

Note: you will obviously need a server to run the program.

There are alot of threads on this kind of thing and even an article here on devshed that should tell you everything you need to know!

Happy huntingm have fun!

Mark.



This is the python source

import time

print "Content-type: text/html"

print "Right now, it is ", time.asctime()

and this is the html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Current Time</title>

</head>
<body>
<h1>Current Time</h1>

</body>
</html>

Reply With Quote
  #6  
Old March 7th, 2004, 09:02 PM
MasterChief MasterChief is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Virginia
Posts: 491 MasterChief User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 47 m 47 sec
Reputation Power: 6
Send a message via AIM to MasterChief Send a message via MSN to MasterChief
Code:
#!/usr/bin/env python
print "Content-Type: text/html\n"
print "<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">"
print "<html xmlns="http://www.w3.org/1999/xhtml">"
print "<head>"
print "<title>Current Time</title>"
print "</head>"
print "<body>"
print "<h1>Current Time</h1>"
print "import time'
print ""Content-type: text/html""
print ""Right now, it is ", time.asctime()"
print "</body>"
print "</html>"


Use single quotes (' ') around your strings.
You don't print the import.

This code should do what you want it to:
Code:
#!/usr/bin/env python
print 'Content-Type: text/html\n'
print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
print '<html xmlns="http://www.w3.org/1999/xhtml">'
print '<head>'
print '<title>Current Time</title>'
print '</head>'
print '<body>'
print '<h1>Current Time</h1>'
import time
time = time.asctime()
print 'Right now, it is '
print time
print '</body>'
print '</html>'


See the script in action on my Apache Web server.

Reply With Quote
  #7  
Old March 8th, 2004, 12:33 AM
sonatas sonatas is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 9 sonatas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up

Quote:
Originally Posted by MasterChief
Code:
#!/usr/bin/env python
print "Content-Type: text/html\n"
print "<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">"
print "<html xmlns="http://www.w3.org/1999/xhtml">"
print "<head>"
print "<title>Current Time</title>"
print "</head>"
print "<body>"
print "<h1>Current Time</h1>"
print "import time'
print ""Content-type: text/html""
print ""Right now, it is ", time.asctime()"
print "</body>"
print "</html>"


Use single quotes (' ') around your strings.
You don't print the import.

This code should do what you want it to:
Code:
#!/usr/bin/env python
print 'Content-Type: text/html\n'
print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
print '<html xmlns="http://www.w3.org/1999/xhtml">'
print '<head>'
print '<title>Current Time</title>'
print '</head>'
print '<body>'
print '<h1>Current Time</h1>'
import time
time = time.asctime()
print 'Right now, it is '
print time
print '</body>'
print '</html>'


See the script in action on my Apache Web server.


ahhhhhhh ty soooooo much!!!!!!!!!!!!!!!!!! At first when I tried out your source, it didn't work till i had a closer look. you saved it has .py and I saved it as .html! You peeps are the greatest!!

sometimes the obvious is unseen ><

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > putting .py onto an xhtml


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway