我正在做一个关于django项目的教程。实际上是凌晨4点51分,我只想让它正常工作。
我的urls.py文件:
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^polls/$', 'polls.views.index'),
)我的views.py文件:
from django.shortcuts import render
# Create your views here.
from django.shortcuts import render_to_response
def index(request):
return render_to_response('index.html')在文件夹模板中,我有index.html文件。它向我展示了相同的TemplateDoesNotExist错误,因此我做了一些研究,并进行了I found this question,因此我在I found this question中添加了以下代码:
import os.path
SITE_ROOT = os.path.dirname(os.path.realpath(__file__))
TEMPLATE_DIRS = (
os.path.join(SITE_ROOT, 'templates/'),
)那么如何让它发挥作用呢?
这是回溯:
使用加载程序的django.template.loaders.app_directories.Loader: C:\Python33\lib\site-packages\django\contrib\admin\templates\index.html (文件不存在) C:\Python33\lib\site-packages\django\contrib\auth\templates\index.html (文件不存在) 回溯:"C:\Python33\lib\site-packages\django\core\handlers\base.py“文件在get_response 114中。响应=索引8中的文件"C:\Users\JD\PycharmProjects\MyDjangoApp\polls\views.py“=wrapped_callback(请求、*callback_args、**callback_kwargs)。在render_to_response 29中返回render_to_response('index.html')文件"C:\Python33\lib\site-packages\django\shortcuts\__init__.py”。返回HttpResponse(loader.render_to_string(*args,**kwargs),**httpresponse_kwargs)文件render_to_string 162。T= get_template(template_name) get_template 138中的文件template_name。模板,"C:\Python33\lib\site-packages\django\template\loader.py“= find_template(template_name) find_template 131中的文件引发TemplateDoesNotExist (名称)异常类型:TemplateDoesNotExist at /轮询/异常值: index.html
发布于 2014-02-12 23:06:18
变化
import os.path
SITE_ROOT = os.path.dirname(os.path.realpath(__file__))至
import os
SITE_ROOT = os.path.dirname(os.path.dirname(__file__))如果您查看您的跟踪,Python正在您的应用程序文件夹中寻找一个模板文件夹,我假设它将是与settings.py相同的文件夹。
另一种方法是将模板文件夹复制到MyDjangoAPP文件夹中。
https://stackoverflow.com/questions/21741762
复制相似问题