2

Tastypie 看起来很有希望,但现在没有那么多了:

http://django-tastypie.readthedocs.org/en/latest/non_orm_data_sources.html

我应该使用 SimpleAPI 还是有更好的解决方案?

4

3 回答 3

1

嗯,我正在使用这个https://github.com/mitar/django-tastypie-mongoengine

于 2012-04-22T09:58:15.040 回答
0

我曾经使用过django-piston。你应该尝试一下,创建一个 rest api 很容易,并且它与 django 集成。

我读过它可以用 MongoEngine 完成,但从未尝试过。

于 2011-12-01T02:29:37.947 回答
0

The finally solution was to use django-tastypie + django-tastypie-mongoengine:

https://github.com/mitar/django-tastypie-mongoengine

Once you have that installed, in your app add a resource.py with code like this:

from models.account import MAccount
from models.company import MCompany


class AccountResource(resources.MongoEngineResource):
        class Meta:
                serializer = CustomSerializer()
                queryset = MAccount.objects.all()
                allowed_methods = ('get', 'post', 'put','delete')
                resource_name = 'account'
                authorization= tastypie_authorization.Authorization()

Then if your urls.py file add this code:

v1_api = api.Api(api_name='v1')
v1_api.register(resources.AccountResource())
urlpatterns += patterns('', (r'^m/api/', include(v1_api.urls)))

Finally, you should be able to hit an API like

/m/api/v1/account/?format=json

于 2014-01-09T18:07:20.500 回答