我想知道如何让 mongoengine 和 djangoRESTframework 相互协作。目前,我的模型是
from mongoengine import *
import datetime
class Blog(Document):
post_id = IntField(unique=True)
title = StringField(max_length=144, required=True)
date_created = DateTimeField(default=datetime.datetime.now)
body = StringField(required=True)
我将序列化程序定义为
from rest_framework.views import APIView
from rest_framework.response import Response
from .models import *
class BlogList(APIView):
"""
Lists all blog posts, or creates a new post
"""
def get(self, request, format=None):
posts = Blog.objects.to_json()
return Response(posts)
但我收到错误
TypeError at /blog/
__init__() takes exactly 1 argument (2 given)
Request Method: GET
Request URL: http://127.0.0.1:8000/blog/
Django Version: 1.5.1
Exception Type: TypeError
Exception Value:
__init__() takes exactly 1 argument (2 given)
这给出了以下回溯
response = callback(request, *callback_args, **callback_kwargs)