根據這post,我想爲我的Android應用程序做一個休息api。但是當我從django rest框架給json的時候,它不支持utf8的話。 這是截圖:django rest框架不顯示utf8文字
這是我的模型:
from __future__ import unicode_literals
from django.db import models
class News(models.Model):
title = models.CharField(max_length=255)
created = models.DateTimeField('auto_now_add = True')
active = models.BooleanField()
def __str__(self):
return self.title.encode('utf8')
這是我的看法:
from django.shortcuts import render
from rest_framework import viewsets
from rest_framework import permissions
from news.models import News
from news.serializers import NewsSerialzer
class NewsViewSet(viewsets.ModelViewSet):
queryset = News.objects.all()
serializer_class = NewsSerialzer
,這是我的串行:
from news.models import News
from rest_framework import serializers
class NewsSerialzer(serializers.HyperlinkedModelSerializer):
class Meta:
model = News
fields = ('title' , 'active' , 'created')
我用django rest框架3.3.2