OoO En ce début d'après-midi nuageux du samedi 16 août 2008, vers 14:50,
Jean-Paul Calderone <[EMAIL PROTECTED]> disait :

> JSON isn't XHTML, and the `docFactory´ and `render_*´ mechanisms are
> primarily concerned with the generation of XHTML.  To generate JSON,
> I think you'd do better to ignore these features of Page and override
> the `renderHTTP´ method instead.  You won't have to deal with < being
> turned into &lt; and other such XHTML-related problems.

Thanks for the tip.

I have added the following function:

,----
|     addSlash = True
| 
|     def renderHTTP(self, ctx):
|         request = inevow.IRequest(ctx)
|         if inevow.ICurrentSegments(ctx)[-1] != '':
|             request.redirect(request.URLPath().child(''))
|             return ''
|         request.setHeader("Content-Type",
|                           "application/json; charset=UTF-8")
|         d = defer.maybeDeferred(self.data_json, ctx, None)
|         d.addCallback(lambda x: self.render_json(ctx, x))
|         return d
`----

This now works fine.

Thanks for your help.
-- 
Test input for validity and plausibility.
            - The Elements of Programming Style (Kernighan & Plauger)

_______________________________________________
Twisted-web mailing list
[email protected]
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web

Reply via email to