Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6d204bf

Browse files
committed
#4550: fix 2.x syntax in webservers howto.
1 parent 50b2b6e commit 6d204bf

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

Doc/howto/webservers.rst

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ simple CGI program::
101101
# enable debugging
102102
import cgitb; cgitb.enable()
103103

104-
print "Content-Type: text/plain;charset=utf-8"
105-
print
104+
print("Content-Type: text/plain;charset=utf-8")
105+
print()
106106

107-
print "Hello World!"
107+
print("Hello World!")
108108

109109
You need to write this code into a file with a ``.py`` or ``.cgi`` extension,
110110
this depends on your web server configuration. Depending on your web server
@@ -278,8 +278,8 @@ following WSGI-application::
278278
#!/usr/bin/env python
279279
# -*- coding: UTF-8 -*-
280280

281-
from cgi import escape
282281
import sys, os
282+
from cgi import escape
283283
from flup.server.fcgi import WSGIServer
284284

285285
def app(environ, start_response):
@@ -288,7 +288,8 @@ following WSGI-application::
288288
yield '<h1>FastCGI Environment</h1>'
289289
yield '<table>'
290290
for k, v in sorted(environ.items()):
291-
yield '<tr><th>%s</th><td>%s</td></tr>' % (escape(k), escape(v))
291+
yield '<tr><th>{0}</th><td>{1}</td></tr>'.format(
292+
escape(k), escape(v))
292293
yield '</table>'
293294

294295
WSGIServer(app).run()
@@ -476,8 +477,8 @@ placeholders.
476477
Python already includes such simple templates::
477478

478479
# a simple template
479-
template = "<html><body><h1>Hello %s!</h1></body></html>"
480-
print template % "Reader"
480+
template = "<html><body><h1>Hello {who}!</h1></body></html>"
481+
print(template.format(who="Reader"))
481482

482483
The Python standard library also includes some more advanced templates usable
483484
through :class:`string.Template`, but in HTML templates it is needed to use

0 commit comments

Comments
 (0)