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 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>"