我正在尝试为Python编码书中的项目制作主页。我茫然为什么我不断出现下面的错误。我将索引文件放置在正确的位置,但是,我一直收到的异常是该模板不存在。
这是我一直收到的错误。
Traceback (most recent call last):
File "C:\Users\foste\Documents\Programming\python_work\Pojects\Ch. 18 Getting Started with Django\meal_planner\meal_env\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\foste\Documents\Programming\python_work\Pojects\Ch. 18 Getting Started with Django\meal_planner\meal_env\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\foste\Documents\Programming\python_work\Pojects\Ch. 18 Getting Started with Django\meal_planner\meal_env\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\foste\Documents\Programming\python_work\Pojects\Ch. 18 Getting Started with Django\meal_planner\planner\views.py", line 5, in index
return render(request, 'planner/index.html')
File "C:\Users\foste\Documents\Programming\python_work\Pojects\Ch. 18 Getting Started with Django\meal_planner\meal_env\lib\site-packages\django\shortcuts.py", line 36, in render
content = loader.render_to_string(template_name, context, request, using=using)
File "C:\Users\foste\Documents\Programming\python_work\Pojects\Ch. 18 Getting Started with Django\meal_planner\meal_env\lib\site-packages\django\template\loader.py", line 61, in render_to_string
template = get_template(template_name, using=using)
File "C:\Users\foste\Documents\Programming\python_work\Pojects\Ch. 18 Getting Started with Django\meal_planner\meal_env\lib\site-packages\django\template\loader.py", line 19, in get_template
raise TemplateDoesNotExist(template_name, chain=chain)
django.template.exceptions.TemplateDoesNotExist: planner/index.html
[22/May/2019 22:01:46] "GET / HTTP/1.1" 500 79939
我的项目名称是餐计划,以下是项目urls.py的代码:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('planner.urls'))
]
以下应用urls.py: “”“为计划者定义网址格式”“”
from django.urls import path
from . import views
app_name = 'planner'
urlpatterns = [
# Home Page
path('', views.index, name='index'),
]
views.py代码:
from django.shortcuts import render
def index(request):
"""The home page for planner"""
return render(request, 'planner/index.html')