wlanslovenija / django-tastypie-mongoengine

MongoEngine support for django-tastypie.
Other
73 stars 59 forks source link

Cannot find User by pk #33

Closed burakkilic closed 11 years ago

burakkilic commented 11 years ago
    class UserResource(resources.MongoEngineResource):
        class Meta:
            queryset = models.User.objects.all()
            allowed_methods = ('get', 'post', 'put', 'delete')
            authorization = authorization.Authorization()
            resource_name = "user"

Here is the "/api/v1/user/" response:

{
  "meta": {
    "limit": 20,
    "next": null,
    "offset": 0,
    "previous": null,
    "total_count": 1
  },
  "objects": [
    {
      "bio": "I'm a computer engineer",
      "contact": {
        "twitter": "xsadasda"
      },
      "email": "asdsdasd@gmail.com",
      "first_name": "Burak",
      "gender": "M",
      "home_city": null,
      "id": "50796e9da5e97c571445d8be",
      "last_name": "Kılıç",
      "outh_tokens": {},
      "photo": null,
      "resource_uri": "/api/v1/user/50796e9da5e97c571445d8be"
    }
  ]
}

When I make "/api/v1/user/50796e9da5e97c571445d8be" , it gives 404 not found. Is something wrong?

mitar commented 11 years ago

Which version are you using?

It seems you are not using trailing slash?

http://django-tastypie.readthedocs.org/en/latest/settings.html#tastypie-allow-missing-slash

burakkilic commented 11 years ago

I tried both with slash and without slash.

Django==1.4.1 django-mongodb-engine==0.4.0 django-tastypie==0.9.11 django-tastypie-mongoengine==0.2.6

mitar commented 11 years ago

No idea. You will have to make a pull request with failing test so that I can try it.

burakkilic commented 11 years ago

I found the bug, but I don't know if it is about django-tastypie-mongoengine or about django-tastypie

If I set #TASTYPIE_ALLOW_MISSING_SLASH = True

In the tastypie.mongoengine resources.py' s obj_get function

kwargs came with the trailing slash if I put it or not.

TASTYPIE_ALLOW_MISSING_SLASH should be false in order to get it worked.

mitar commented 11 years ago

Have you read documentation: _You must also have settings.APPENDSLASH = False so that Django does not emit HTTP 302 redirects. You have this?

burakkilic commented 11 years ago

My settings:

Tastypie

TASTYPIE_ALLOW_MISSING_SLASH = True APPEND_SLASH = False

Still same 404.

mitar commented 11 years ago

Maybe your browser caches redirects? So where is / appended? So if you open /api/v1/user/50796e9da5e97c571445d8be, how it is possible that slash is added to kwargs?

burakkilic commented 11 years ago

I don't know where it is appended. TASTYPIE_ALLOW_MISSING_SLASH = False works ok.

mitar commented 11 years ago

Please make a test.