# settings.py
INSTALLED_APPS = [
rest_framework
]
-
# urls.py
class StorySerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Story
fields = ('name', 'description')
class StoryViewSet(viewsets.ModelViewSet):
queryset = Story.objects.all()
serializer_class = StorySerializer
router = routers.DefaultRouter()
router.register('stories', StoryViewSet)
urlpatterns = [
url(r'^', include(router.urls)),
url(r'^api/', include('rest_framework.urls', namespace='rest_framework'))
]
-
# 浏览器
http://localhost:8000
TemplateDoesNotExist at /
rest_framework/api.html
Request Method: GET
Request URL: http://localhost:8000/
Django Version: 1.9
Exception Type: TemplateDoesNotExist
Exception Value: rest_framework/api.html
Exception Location: /usr/local/lib/pypy/site-packages/django/template/loader.py in get_template, line 43
Python Executable: /usr/local/lib/pypy/bin/pypy
Python Version: 2.7.10
Python Path:
['/Users/tracy/Desktop/pypy/todo',
'/Users/tracy/Desktop/pypy/todo',
'/usr/local/lib/pypy/lib_pypy/__extensions__',
'/usr/local/lib/pypy/lib_pypy',
'/usr/local/lib/pypy/lib-python/2.7',
'/usr/local/lib/pypy/lib-python/2.7/lib-tk',
'/usr/local/lib/pypy/lib-python/2.7/plat-darwin',
'/usr/local/lib/pypy/lib-python/2.7/plat-mac',
'/usr/local/lib/pypy/lib-python/2.7/plat-mac/lib-scriptpackages',
'/usr/local/lib/pypy/site-packages']
Server time: Wed, 23 Dec 2015 13:28:33 +0000
Template-loader postmortem
Django tried loading these templates, in this order:
Using engine django:
django.template.loaders.filesystem.Loader: /Users/tracy/Desktop/pypy/todo/templates/rest_framework/api.html (Source does not exist)
怎么解决?