我正在尝试为Django REST API框架执行this tutorial。
使用我的Apache设置进行测试时,在尝试浏览页面时出现此错误:
TemplateDoesNotExist at /
rest_framework/api.html
但是,如果我通过运行python ./manage.py runserver
测试Python测试Web服务器,它可以正常工作。
我需要在Apache中进行一些配置更改才能修复此问题吗?
提前致谢。
修改
我注意到它正在查找文件的错误位置:
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
Using loader django.template.loaders.app_directories.Loader:
/usr/local/lib/python2.7/dist-
packages/django/contrib/auth/templates/rest_framework/api.html (File does not exist)
但是我无法找到改变它的地方。
答案 0 :(得分:2)
我通过创建虚拟环境并相应地配置Apache解决了这个问题:
WSGIPythonPath /path/to/mysite.com:/path/to/your/venv/lib/python2.X/site-packages