社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  问与答

django-rest-framework 出现 TemplateDoesNotExist

this • 8 年前 • 7213 次点击  
# 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)

怎么解决?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/1387
 
7213 次点击  
文章 [ 3 ]  |  最新文章 8 年前
pyzealot
Reply   •   1 楼
pyzealot    8 年前

能注明一下DJANGO的版本吗?

1131909224
Reply   •   2 楼
1131909224    8 年前

请问用django写REST api,功能为对mongodb中的数据进行增删改查(对应POST、DELETE、PUT、GET4个请求),应该是要怎么写呢

this
Reply   •   3 楼
this    8 年前

已解决

settings.py

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [
        'templates',
    ],
    'APP_DIRS': True, // 这里设置为True
    'OPTIONS': {
        'context_processors': [
            'django.template.context_processors.debug',
            'django.template.context_processors.request',
            'django.contrib.auth.context_processors.auth',
            'django.contrib.messages.context_processors.messages',
        ],
    },
},]