在为 django 配置活塞时遇到问题,每次我指定它运行的模型名称时,都会出现以下错误
RuntimeError at /en/vehicle/api/car.json
Circular reference detected while emitting response
Request Method: GET
Request URL: http://127.0.0.1:8000/en/vehicle/api/car.json
Django Version: 1.4.1
Exception Type: RuntimeError
Exception Value:
Circular reference detected while emitting response
Exception Location: /Users/mo/Projects/pythonic/gar-env/lib/python2.7/site-packages/piston/emitters.py in _any, line 109
Python Executable: /Users/mo/Projects/pythonic/gar-env/bin/python
下面是我的handelrs.py
from piston.handler import BaseHandler
from piston.utils import rc, throttle, translate_mime
from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage
from django.core.urlresolvers import reverse
from django.db.models.loading import get_model
from models import (ModelLookUpI18n as ModelLookup, Image)
from forms import CarForm, ModelLookUpForm, ModelLookUpI18nForm
from django.http import HttpResponse
import logging, json, os
from piston.utils import validate
from django.conf import settings
from django.utils.translation import ugettext as _
class CarHandler(BaseHandler):
"""
CarHandler
"""
allowed_methods = ('GET', 'POST', 'PUT', 'DELETE')
model = Car
fields = ('id', 'model', 'description', 'primary_image', 'color', 'mileage', 'view_count', 'asking_price')
def read(self, request):
params = dict()
params.update({'status' : self.model.STATUS_ACTIVE})
return self.model.objects.filter(**params).order_by('created_at')
在 url.py 这是我的代码
from django.conf.urls import *
from handlers import CarHandler
from piston.resource import Resource
car_resource = Resource(CarHandler)
# API URL schema
urlpatterns += patterns('',
# car API
url(r'^api/car\.(?P<emitter_format>.+)', car_resource, name='vehicle-api-car'),
)
错误出现在运行时,我找不到问题的解决方案。我试图从 CarHandler 类中删除模型和字段属性,使其工作。我厌倦了使用 get_model 并在运行时加载,但同样,我会得到相同的运行时错误。
请指教?