Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #27240

Re: [CGI] Why is HTML not rendered?

From Robert Kern <robert.kern@gmail.com>
Subject Re: [CGI] Why is HTML not rendered?
Date 2012-08-17 14:44 +0100
References <hihs289062ottjtqpgpkbl3pb6b1irj9kq@4ax.com>
Newsgroups comp.lang.python
Message-ID <mailman.3415.1345211095.4697.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[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

csiph-web