On 21/05/14 16:50, fabu desay wrote:
If I got the problem correctly,you can equally create + open a file
file = open(filename,+wr)
You wouldn't normally use +wr as a mode; that introduces a lot of
complications. Usually you just open to read, or open to write.
In your case w is all you need.
The file should have the HTML extension
You can now pace your web contents in the file.html you created
that should work by trigering the python file you programed in and it
inturn creates the website or pages of your choice
I'm not totally sure what you mean but I don;t think it works the way
you believe.
What you do in your code below is create an HTML file.
That could be served up by a web server as a static HTML file.
But for dynamic web content the program actually prints the HTML
to stdout and the web server redirects stdout back to the web
client(browser).
an example like this could help
webpage = open('index.html', 'w+')
webpage.write("<html><head><title>My web page</title></head>");
webpage.write("<body>This the body</body></html>");
webpage.close()
You don't need the w+, w on its own is adequate.
And you don't need semi-colons at the end of lines.
But basically this just creates a text file in a folder somewhere.
Its only when that is accessed via a web server that it gets
sent to a browser, and only as a static file.
If you wanted to do it dynamically you'd have a file called
something like mypage.cgi which looked like:
print("<html><head><title>My web page</title></head>")
print("<body>This the body</body></html>")
And provided the web server was configured to run python
on cgi files you could access it as
http://myserver.addresss/mypage.cgi
HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor