Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #27238 > unrolled thread
| Started by | Gilles <nospam@nospam.com> |
|---|---|
| First post | 2012-08-17 15:27 +0200 |
| Last post | 2012-08-17 15:40 +0200 |
| Articles | 5 — 4 participants |
Back to article view | Back to comp.lang.python
[CGI] Why is HTML not rendered? Gilles <nospam@nospam.com> - 2012-08-17 15:27 +0200
Re: [CGI] Why is HTML not rendered? Dan Sommers <dan@tombstonezero.net> - 2012-08-17 06:41 -0700
Re: [CGI] Why is HTML not rendered? Robert Kern <robert.kern@gmail.com> - 2012-08-17 14:44 +0100
Re: [CGI] Why is HTML not rendered? Gilles <nospam@nospam.com> - 2012-08-17 18:19 +0200
Re: [CGI] Why is HTML not rendered? Alexander Blinne <news@blinne.net> - 2012-08-17 15:40 +0200
| From | Gilles <nospam@nospam.com> |
|---|---|
| Date | 2012-08-17 15:27 +0200 |
| Subject | [CGI] Why is HTML not rendered? |
| Message-ID | <hihs289062ottjtqpgpkbl3pb6b1irj9kq@4ax.com> |
Hello
I'm learning how to call Python scripts through the different
solutions available.
For some reason, this CGI script that I found on Google displays the
contents of the variable but the HTML surrounding it is displayed
as-is by the browser instead of being rendered:
--------------
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# enable debugging
import cgitb
cgitb.enable()
import cgi
form = cgi.FieldStorage()
# get a value from the form
value = form.getvalue("dummy")
print "Content-Type: text/plain;charset=utf-8"
print
# print a document
print "<P>You typed: <TT>%s</TT></P>" % (
cgi.escape(value),
)
--------------
Here's the output:
--------------
<P>You typed: <TT>test</TT></P>
--------------
Could this be due to the script itself, or some server configuration?
Thank you.
[toc] | [next] | [standalone]
| From | Dan Sommers <dan@tombstonezero.net> |
|---|---|
| Date | 2012-08-17 06:41 -0700 |
| Message-ID | <mailman.3414.1345210924.4697.python-list@python.org> |
| In reply to | #27238 |
On 2012-08-17 at 15:27:59 +0200,
Regarding "[CGI] Why is HTML not rendered?,"
Gilles <nospam@nospam.com> wrote:
> For some reason, this CGI script that I found on Google displays the
> contents of the variable but the HTML surrounding it is displayed
> as-is by the browser instead of being rendered:
... [with all due respect and apologies to another thread on this list!]
> print "Content-Type: text/plain;charset=utf-8"
That line tells the browser that the response is plain text.
Do this instead to have the browser render the HTML:
print "Content-Type: text/html;charset=utf-8"
HTH,
Dan
--
Μὴ μοῦ τοὺς κύκλους τάραττε -- Αρχιμηδησ
Do not disturb my circles. -- Archimedes
Dan Sommers, http://www.tombstonezero.net/dan
[toc] | [prev] | [next] | [standalone]
| From | Robert Kern <robert.kern@gmail.com> |
|---|---|
| Date | 2012-08-17 14:44 +0100 |
| Message-ID | <mailman.3415.1345211095.4697.python-list@python.org> |
| In reply to | #27238 |
On 8/17/12 2:27 PM, Gilles wrote:
> Hello
>
> I'm learning how to call Python scripts through the different
> solutions available.
>
> For some reason, this CGI script that I found on Google displays the
> contents of the variable but the HTML surrounding it is displayed
> as-is by the browser instead of being rendered:
>
> --------------
> #!/usr/bin/env python
> # -*- coding: UTF-8 -*-
>
> # enable debugging
> import cgitb
> cgitb.enable()
>
> import cgi
> form = cgi.FieldStorage()
>
> # get a value from the form
> value = form.getvalue("dummy")
>
> print "Content-Type: text/plain;charset=utf-8"
> print
>
> # print a document
> print "<P>You typed: <TT>%s</TT></P>" % (
> cgi.escape(value),
> )
> --------------
>
> Here's the output:
> --------------
> <P>You typed: <TT>test</TT></P>
> --------------
>
> Could this be due to the script itself, or some server configuration?
By using "Content-Type: text/plain", you told the browser to treat it like plain
text instead of HTML. Use text/html instead.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
[toc] | [prev] | [next] | [standalone]
| From | Gilles <nospam@nospam.com> |
|---|---|
| Date | 2012-08-17 18:19 +0200 |
| Message-ID | <qmrs28tpmjuvapk72f0st6u1fnjg3l8u1h@4ax.com> |
| In reply to | #27240 |
On Fri, 17 Aug 2012 14:44:37 +0100, Robert Kern <robert.kern@gmail.com> wrote: >> For some reason, this CGI script that I found on Google displays the >> contents of the variable but the HTML surrounding it is displayed >> as-is by the browser instead of being rendered Thanks all. I (obviously) combined two scripts but didn't notice that I had to change the "Content-Type" line to output HTML.
[toc] | [prev] | [next] | [standalone]
| From | Alexander Blinne <news@blinne.net> |
|---|---|
| Date | 2012-08-17 15:40 +0200 |
| Message-ID | <502e49ca$0$6558$9b4e6d93@newsspool4.arcor-online.net> |
| In reply to | #27238 |
On 17.08.2012 15:27, Gilles wrote: > For some reason, this CGI script that I found on Google displays the > contents of the variable but the HTML surrounding it is displayed > as-is by the browser instead of being rendered: > print "Content-Type: text/plain;charset=utf-8" With this line you tell the browser to expect a simple plain text file and no html. Change the line to print "Content-Type: text/html;charset=utf-8" and it should work.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web