python for web

s0nicpulse

n00b
Joined
Oct 25, 2003
Messages
22
Hey everyone
So I spent a couple of hours today messing around with writing python for the web, and I am beyond frustration :(
I can't get a simple form to work , and I can't get a script to add lines to a text file... if anyone can help and suggest what may be wrong with my code? Or if what I'm trying to do is possible? I'm pretty sure it is though....

For background, I'm planning on making a very simple weblog program written in python for the web. Very simple things like a user logs in, writes a post and it gets put into the main page...

main page for form:

#! C:\FoxServ\python\python.exe
print "Content-Type: text/html\n\n"

print """<FORM METHOD=GET ACTION="form.py">
What is your favorite color?
<INPUT TYPE=TEXT NAME=field SIZE=20 MAXLENGTH=64>
</FORM>"""


form.py :

#! C:\FoxServ\python\python.exe
print "Content-Type: text/html\n\n"


form = cgi.FieldStorage()
print field
print form[field]

For the reading and writing to a file

#!C:\FoxServ\python\python.exe
# Tell the browser type of the output
print "Content-Type: text/html\n\n"

# Print output
print """<HTML><HEAD>
<TITLE>wats up</TITLE>
</HEAD><BODY>"""

input_file = open('news.txt','w')
a=input_file.read()
print a
print "<br><br>"
print "---hello---"
input_file.writelines('hey!')
b=input_file.read()
print b

print input_file

print "</BODY></HTML>"
 
So, are you getting -any- output? Just that 'this doesn't work' doesn't help any.

you probably want to use writeline() instead of writelines(), since you're only using one string. It'll work the way it is, but writelines is supposted to be for lists...

You might be having problems with file permissions on the output file. Wrap some of it up & look for exceptions; see what happens.
 
Back
Top