Tastypie 看起来很有希望,但现在没有那么多了:
http://django-tastypie.readthedocs.org/en/latest/non_orm_data_sources.html
我应该使用 SimpleAPI 还是有更好的解决方案?
Tastypie 看起来很有希望,但现在没有那么多了:
http://django-tastypie.readthedocs.org/en/latest/non_orm_data_sources.html
我应该使用 SimpleAPI 还是有更好的解决方案?
我曾经使用过django-piston。你应该尝试一下,创建一个 rest api 很容易,并且它与 django 集成。
我读过它可以用 MongoEngine 完成,但从未尝试过。
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