我是Django的新手。因此,我正在尝试将HTML模板添加到views.py
中,但是它显示了一个错误,如果您能帮助我,那就太好了。
我看到的完整错误:
TemplateDoesNotExist at /
platform/home.html
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 3.0.8
Exception Type: TemplateDoesNotExist
Exception Value:
platform/home.html
Exception Location: C:\Users\Adeel\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\template\loader.py in get_template, line 19
Python Executable: C:\Users\Adeel\AppData\Local\Programs\Python\Python38-32\python.exe
Python Version: 3.8.3
Python Path:
['C:\\Users\\Adeel\\Google Drive\\Visual Studio\\Personal Portfolio\\Portfolio',
'C:\\Users\\Adeel\\AppData\\Local\\Programs\\Python\\Python38-32\\python38.zip',
'C:\\Users\\Adeel\\AppData\\Local\\Programs\\Python\\Python38-32\\DLLs',
'C:\\Users\\Adeel\\AppData\\Local\\Programs\\Python\\Python38-32\\lib',
'C:\\Users\\Adeel\\AppData\\Local\\Programs\\Python\\Python38-32',
'C:\\Users\\Adeel\\AppData\\Roaming\\Python\\Python38\\site-packages',
'C:\\Users\\Adeel\\AppData\\Local\\Programs\\Python\\Python38-32\\lib\\site-packages',
'C:\\Users\\Adeel\\AppData\\Local\\Programs\\Python\\Python38-32\\lib\\site-packages\\win32',
'C:\\Users\\Adeel\\AppData\\Local\\Programs\\Python\\Python38-32\\lib\\site-packages\\win32\\lib',
'C:\\Users\\Adeel\\AppData\\Local\\Programs\\Python\\Python38-32\\lib\\site-packages\\Pythonwin']
Server time: Tue, 13 Oct 2020 06:14:44 +0000
views.py:
from django.shortcuts import render
def home(request):
return render(request, 'platform/home.html')
urls.py:
from django.contrib import admin
from django.urls import path
from django.conf.urls.static import static
from django.conf import settings
from Platform import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.home, name='Home'),
]
settings.py:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': 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',
],
},
},
]
我要添加的HTML模板:
<h1>This is my project</h1>
答案 0 :(得分:0)
将模板添加到目录中
def home(request):
return render(request, 'home.html')
之后
from . import views
希望我什么都没错过
编辑
您应该有一个包含模板的单独文件夹
和urls.py
中namespace Memorise
{
public interface ISQLiteDB1
{
(SQLiteConnection, bool) GetConnection();
}
}