[英]How do I create simple REST APIs in Django with a MongoEngine backend?
Tastypie looked promising, now not so much: Tastypie看起来很有前途,但现在还不那么多:
http://django-tastypie.readthedocs.org/en/latest/non_orm_data_sources.html http://django-tastypie.readthedocs.org/en/latest/non_orm_data_sources.html
Should I use SimpleAPI or is there a better solution? 我应该使用SimpleAPI还是有更好的解决方案?
The finally solution was to use django-tastypie + django-tastypie-mongoengine: 最终的解决方案是使用django-tastypie + django-tastypie-mongoengine:
https://github.com/mitar/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: 安装完成后,在您的应用程序中添加带有以下代码的resource.py:
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: 然后,如果您的urls.py文件添加以下代码:
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 /米/ API / V1 /帐户/?格式= JSON
I once used django-piston . 我曾经用过django-活塞 。 You should try it out, it's easy to create a rest api and it's integrated with django.
您应该尝试一下,创建rest api很容易,并且它与django集成在一起。
I've read it can be done with MongoEngine, but never tryed. 我读过它可以用MongoEngine完成,但从未尝试过。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.