Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tastypie return empty resource_uri in get

This is the resource

class TagResource(ModelResource):
    user = tastypie.fields.ForeignKey(UserResource,'user')

    class Meta:
        queryset = Tag.objects.all()
        resource_name = 'tag'
        authorization= Authorization()
        object_class = Tag
        filtering = { 
            'name' : ALL, 
        }

simple get request

http://localhost:8000/api/v1/tag/1/?format=json

returns with empty resource_uri

{"created": "2014-03-26T15:14:11.928068", 
 "id": 1, "name": "test", 
 "resource_uri": "", "user": ""}

Why is that ?

I tried

def hydrate_resource_uri(self, bundle): 
  return bundle.get_resource_uri()

It didn't work and i'm pretty sure it's not supposed to require special care.

What am i missing ?

like image 977
haki Avatar asked Feb 13 '23 09:02

haki


2 Answers

I know this is old, but I know your problem, I just had it on mine, you have a "namespace" on the API URL include or on any URL includes further up in your URL tree.

like image 141
byoungb Avatar answered Feb 16 '23 10:02

byoungb


I had the same problem, and it was because I forgot to register my resource in the urls.py. Ensure you have something like this in your urls.py file:

myapi.register(TagResource())
like image 31
David D. Avatar answered Feb 16 '23 12:02

David D.