1. Jesper Noehr
  2. django-piston
  3. Issues
Issue #54 resolved

Got an error on piston 0.2.2 'Blogpost' object has no attribute 'format'

Anonymous created an issue

Hi all,

I run piston example with Django 1.02; when I open url: http://localhost:8000/api/posts/ It cause some errors and reports: Blogpost' object has no attribute 'format' But if I remove some statements in the blogpost/api/handler.py 13 くらめそ 14 def resource_uri(self): 15 return ('blogposts', [ 'format', ]) and it works fine. Does anyone know what problem is it?

The detail error msg: Environment:

Request Method: GET Request URL: http://localhost:8000/api/posts/ Django Version: 1.0.2 final Python Version: 2.6.2 Installed Applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.admin', 'django.contrib.markup', 'blogserver.blog', 'blogserver.api'] Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware')

Traceback: File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site-packages/django/core/handlers/base.py" in get_response 86. response = callback(request, callback_args, callback_kwargs) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site-packages/django/views/decorators/vary.py" in inner_func 21. response = func(*args, kwargs) File "/Users/wuyiting/Desktop/django-piston/examples/blogserver/../../ piston/resource.py" in call 172. else: stream = srl.render(request) File "/Users/wuyiting/Desktop/django-piston/examples/blogserver/../../ piston/emitters.py" in render 367. seria = simplejson.dumps(self.construct(), cls=DateTimeAwareJSONEncoder, ensure_ascii=False, indent=4) File "/Users/wuyiting/Desktop/django-piston/examples/blogserver/../../ piston/emitters.py" in construct 276. return _any(self.data, self.fields) File "/Users/wuyiting/Desktop/django-piston/examples/blogserver/../../ piston/emitters.py" in _any 91. ret = _qs(thing, fields=fields) File "/Users/wuyiting/Desktop/django-piston/examples/blogserver/../../ piston/emitters.py" in _qs 261. return [ _any(v, fields) for v in data ] File "/Users/wuyiting/Desktop/django-piston/examples/blogserver/../../ piston/emitters.py" in _any 99. ret = _model(thing, fields=fields) File "/Users/wuyiting/Desktop/django-piston/examples/blogserver/../../ piston/emitters.py" in _model 243. ret['resource_uri'] = permalink( lambda: (url_id, File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site-packages/django/db/models/init.py" in inner 30. return reverse(bits[0], None, bits[1:3]) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ site-packages/django/core/urlresolvers.py" in reverse 254. args, *kwargs))) File "/Users/wuyiting/Desktop/django-piston/examples/blogserver/../../ piston/emitters.py" in <genexpr> 244. (getattr(data, f) for f in fields) ) ) ()

Exception Type: AttributeError at /api/posts/ Exception Value: 'Blogpost' object has no attribute 'format'

Comments (7)

  1. Anonymous

    "me to"

    Although i also found that if you remove the format parts you've mentioned, then the non-api view also fails to work. So it's a case of one, or the other. :(

  2. Anonymous

    I can confirm that the above patch is applied to the version i am using (92644a459862 ) has the above patch applied:

    api/handlers.py, line 34: def read(self, request, title=None):

    However, the reported behaviour in this bug is still happening. :(

  3. Anonymous

    For the example project blogserver, In the file api/handlers.py you need to change the word 'format' to 'title', ie:

    # I replaced format to title in the following example;
    def resource_uri(self):
            return ('blogposts', [ 'title', ])
  4. Log in to comment