1.
def retrieve(self, request, pk=None): try: book = Book.objects.get(book_id=pk) except Book.DoesNotExist: return HttpResponse(status=404) # queryset = Book.objects.all() # book = get_object_or_404(queryset, pk=pk) serializer = BookSerializer(book) return Response(serializer.data)
http://www.cnblogs.com/pycode/p/6365905.html
http://www.django-rest-framework.org/api-guide/viewsets/
2.boostrap
http://www.cnblogs.com/fnng/p/3998774.html
3.
class Category(models.Model): categoryid = models.IntegerField(default=0) createtime = models.IntegerField(default=0) display = models.IntegerField(default=0) uses = models.IntegerField(default=0) entitle = models.CharField(max_length=255, unique=True) zhtitle = models.CharField(max_length=255, unique=True) intro = models.TextField(blank=True) miniposter = models.CharField(max_length=255, unique=True) poster = models.CharField(max_length=255, unique=True) status = models.IntegerField(default=0) topcatid = models.IntegerField(default=0) def __unicode__(self): return '%s' % self.entitleclass Theme(models.Model): themeid = models.IntegerField(default=0) category = models.ForeignKey(Category) display = models.IntegerField(default=0) grade = models.IntegerField(default=0) intro = models.TextField(blank=True) poster = models.CharField(max_length=255, unique=True) status = models.IntegerField(default=0) uses = models.IntegerField(default=0) tips = models.CharField(max_length=255, blank=True) title = models.CharField(max_length=255, unique=True) def __unicode__(self): return '%s' % self.title
class ThemeSerializer(serializers.HyperlinkedModelSerializer): category = CategorySerializer() class Meta: model = Theme fields = ('category', 'display', 'grade', 'intro', 'poster', 'status', 'themeid', 'uses', 'title', 'tips')class ThemeSet(viewsets.ModelViewSet): queryset = Theme.objects.all() serializer_class = ThemeSerializer
http://python.jobbole.com/87226/