[Grok-dev] Re: Using POST request

Uli Fouquet uli at gnufix.de
Fri Mar 21 13:47:49 EDT 2008


Hi there,

Martijn Faassen wrote:

> Note that the alternative pattern would be to use an Index view:
> 
> class Index(grok.View):
>     grok.context(eggserver)
>     def render(self):
>         if self.request.method == 'POST':
>              ....
> 
> It's weird though that the REST story doesn't seem to be working; I 
> suspect we're missing something simple, but what?

Worse: also the view seems not to work with setup.py requests (Grok
0.11.1):

import grok
class eggserver(grok.Application, grok.Model):
    """ my content class """
    pass

class Index(grok.View):
    grok.context(eggserver)

    def __init__(self, *args, **kw):
        super(Index, self).__init__(*args, **kw)
        # Just to make sure, something happened...
        print "INDEX CREATED"
        
    def render(self):
        if self.request.method == 'POST':
            return 'blah'
        elif self.request.method == 'GET':
            return 'blubb'
        else:
            print "Somethin else"

This should at least return _something_ in case of POST requests,
shouldn't it? For simple, malformed POST requests, this is the case::

  $ telnet localhost 8080 Trying 127.0.0.1...
  Connected to lo.
  Escape character is '^]'.
  POST /eggs HTTP/1.0

  HTTP/1.1 200 OK
  Content-Length: 6
  X-Powered-By: Zope (www.zope.org), Python (www.python.org)
  Accept-Ranges: bytes
  Server: Twisted/2.5.0 TwistedWeb/[twisted.web2, version 0.2.0]
  X-Content-Type-Warning: guessed from content
  Date: Fri, 21 Mar 2008 16:51:24 GMT
  Content-Type: text/plain
  Connection: close

  blah
  Connection closed by foreign host.

It also works for GET and for browser generated POST requests of any
kind (url-encoded and multipart/form-data). But not for setup.py POST
requests.

The view object is even not created upon request, although setup.py
sends a complex but (at first glance) regular POST request. The same is
true for Andreas' ``MyREST2`` class. It is even not asked for generating
content (for GET requests it works, also for browser generated
multipart/form POST requests). What's wrong here? Maybe something
strange in the setup.py request? Anyway, the problem does not seem to be
REST specific.

Best regards,

-- 
Uli

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://mail.zope.org/pipermail/grok-dev/attachments/20080321/03c4b6ff/attachment.bin


More information about the Grok-dev mailing list