gpt4 book ai didi

django - 模板不存在

转载 作者:行者123 更新时间:2023-12-02 08:50:10 25 4
gpt4 key购买 nike

我是 Django 新手。我使用 pydev eclipse 作为 IDE。首先,我创建了一个项目,然后在该项目上创建了一个欢迎应用程序。我在项目中创建了一个名为 Templates 的文件夹,并创建了一个文件“home.html”,home.html 包含

<div>
This is my first site
</div>

我将settings.py文件修改为

TEMPLATE_DIRS = ("Templates")

INSTALLED_APPS = (
..........#all default items
'welcome', #the added one
)

views.py 包含

from django.shortcuts import render_to_response
def home(request):
return render_to_response('home.html')

urls.py 包含

from django.conf.urls import patterns, include, url
from welcome.views import home
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
# Examples:
# url(r'^$', 'MajorProject.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),

url(r'^admin/', include(admin.site.urls)),
url(r'^home/$', home),

)

然后我将其作为 django 项目运行并打开浏览器并在 localhost:8000/home 上查看它显示错误

TemplateDoesNotExist at /home/
home.html
Request Method: GET
Request URL: http://localhost:8000/home/
Django Version: 1.6
Exception Type: TemplateDoesNotExist
Exception Value:
home.html
Exception Location: C:\Python27\django\template\loader.py in find_template, line 131
Python Executable: C:\Python27\python.exe
Python Version: 2.7.2
Python Path:
['D:\\Bishnu\\BE\\4th year\\8th semester\\Major Project II\\Working\\Workspace\\MajorProject',
'C:\\Python27\\lib\\site-packages\\distribute-0.6.35-py2.7.egg',
'D:\\Bishnu\\BE\\4th year\\8th semester\\Major Project II\\Working\\Workspace\\MajorProject',
'C:\\Python27\\DLLs',
'C:\\Python27\\lib',
'C:\\Python27\\lib\\plat-win',
'C:\\Python27\\lib\\lib-tk',
'C:\\Python27',
'C:\\Python27\\lib\\site-packages',
'C:\\Python27\\lib\\site-packages\\wx-2.8-msw-unicode',
'C:\\Windows\\SYSTEM32\\python27.zip']
Server time: Sun, 2 Jun 2013 14:25:52 +0545

最佳答案

尝试在 setting.py 上设置模板目录。

TEMPLATE_DIRS = (
os.path.join(os.path.dirname(__file__),'templates'),
)

关于django - 模板不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16870957/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com