django /basicapp/index.html中不存在模板

nqwrtyyt  于 2022-12-24  发布在  Go
关注(0)|答案(1)|浏览(184)

'大家好,朋友们,我试着用django创建基本表单,直接从Python和Django Full Stack Web Developer Bootcamp的例子开始。
/basicapp/index.html中不存在模板请求方法:GET请求URL:http://127.0.0.1:8000/ Django版本:4.1.3异常类型:模板不存在异常值:
异常位置:C:\用户\管理员\应用数据\本地\程序\Python\Python311\库\站点包\django\模板\加载器. py,第19行,在get_template中在以下过程中引发:Python可执行文件:C:\Users\ADMIN\AppData\Local\Programs\Python\Python311\python.exe
Python版本:3.11.0
template-loader postmortem Django尝试加载这些模板,顺序如下:
使用引擎django:
django.template.loaders.filesystem.Loader: C:\Users\ADMIN\Desktop\Django\Django_forms\basic_forms\templates,\basicapp\index.html (Source does not exist) django.template.loaders.app_directories.Loader: C:\Users\ADMIN\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\contrib\admin\templates\basicapp\index.html (Source does not exist) django.template.loaders.app_directories.Loader: C:\Users\ADMIN\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\contrib\auth\templates\basicapp\index.html (Source does not exist)
这是我的设置。py

from pathlib import Path
import os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
TEMPLATE_DIR = os.path.join(BASE_DIR,"templates,")

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-bdh2@$^s84&+%qn^atqa+xjz8@7&g=(m2^!5j$f#$o=4+7jb5s'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    "basicapp",
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'basic_forms.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [TEMPLATE_DIR],
        'APP_DIRS': True,`



**View.py**

从django.shortcuts导入渲染从. import表单

在此处创建视图。

x一个一个一个一个x一个一个二个x
从django.contrib导入管理员从django.urls导入路径从basicapp导入视图
一个三个三个一个
从django导入表单
类表单名称(表单. Form):名称=表单.字符字段()'电子邮件=表单.电子邮件字段()文本=表单.字符字段(小部件=表单.文本区域)

`
8xiog9wr

8xiog9wr1#

您得到templates does not exist是因为您在TEMPLATE_DIR中添加了comma

TEMPLATE_DIR = os.path.join(BASE_DIR,"templates") #let's remove comma from here.

现在这将工作!

相关问题