Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:: [': 0.03; 'debugging': 0.05; '%s"': 0.07; '-*-': 0.07; 'reason,': 0.07; 'utf-8': 0.07; 'scripts': 0.09; 'python': 0.09; 'coding:': 0.09; 'itself,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:Why': 0.09; 'underlying': 0.09; 'subject:not': 0.11; 'as- is': 0.16; 'gilles': 0.16; 'kern': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'wrote:': 0.17; 'subject:] ': 0.19; 'variable': 0.20; 'import': 0.21; 'displayed': 0.22; 'interpret': 0.22; 'script': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'plain': 0.27; 'skip:# 10': 0.27; 'displays': 0.27; 'instead.': 0.27; 'header:X-Complaints-To:1': 0.28; 'cgi': 0.29; "i'm": 0.29; 'skip:- 10': 0.32; 'could': 0.32; 'print': 0.32; 'to:addr:python-list': 0.33; 'text': 0.34; 'server': 0.35; 'robert': 0.35; 'pm,': 0.35; 'subject:?': 0.35; 'received:org': 0.36; 'but': 0.36; 'test': 0.36; 'available.': 0.37; 'being': 0.37; 'some': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'google': 0.39; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'enable': 0.60; 'different': 0.63; 'world': 0.63; 'our': 0.65; 'treat': 0.65; 'due': 0.66; 'believe': 0.69; 'eco': 0.84; 'terrible': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Robert Kern Subject: Re: [CGI] Why is HTML not rendered? Date: Fri, 17 Aug 2012 14:44:37 +0100 References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 213.1.240.227 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:14.0) Gecko/20120713 Thunderbird/14.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 51 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1345211095 news.xs4all.nl 6978 [2001:888:2000:d::a6]:54844 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:27240 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 "

You typed: %s

" % ( > cgi.escape(value), > ) > -------------- > > Here's the output: > -------------- >

You typed: test

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