Django,TastyPie commit_on_success错误

时间:2015-06-30 16:34:28

标签: python django tastypie

我正在尝试将TastyPie添加到我的Django项目中以构建RESTful API。我正在使用Django 1.8.2。我正在关注official tutorial。 我创建了一个资源:

# myapp/api.py
from tastypie.resources import ModelResource
from myapp.models import Entry


class RecipeResource(ModelResource):
    class Meta:
        queryset = Entry.objects.all()

# urls.py
from django.conf.urls import include, url
from django.contrib import admin
from myapp.api import RecipeResource

recipe_resource = RecipeResource()

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^api/', include(recipe_resource.urls)),
]

我不认为这个问题出现在我的代码中,因为它几乎是一个副本&从教程粘贴。执行导入时发生错误:

from myapp.api import RecipeResource

我是Django和TastyPie的新手。可能是TastyPie不能与Django 1.8.2一起使用吗?

错误:

  File "/Users/rafalsroka/Documents/Pthn/Recipes/recipes-backend/lib/python2.7/site-packages/tastypie/resources.py", line 1740, in <module>
    class BaseModelResource(Resource):
  File "/Users/rafalsroka/Documents/Pthn/Recipes/recipes-backend/lib/python2.7/site-packages/tastypie/resources.py", line 2210, in BaseModelResource
    @transaction.commit_on_success()
AttributeError: 'module' object has no attribute 'commit_on_success'

1 个答案:

答案 0 :(得分:2)

看起来TastyPie 缺少Django 1.8.2的支持。 此版本的commit_on_success已删除Django

我想使用最新版本,所以切换到Django Rest Framework