python - 如何使用 CreateView?django.template.exceptions.TemplateDoesNotExist:django/forms/widgets/text.html
问题描述
我想使用 CreateView。但是,它会生成错误 django.template.exceptions.TemplateDoesNotExist:django/forms/widgets/text.html
根/accounting_report/views.py
from django.views.generic import CreateView
from .models import AccountingReport
class ReportCreateView(CreateView):
model = AccountingReport
fields = ['name','receipts','expenses','user_id']
success_url="accounting_report/"
根/accounting_report/urls.py
from django.urls import path
from accounting_report.views import ReportCreateView
urlpatterns = [
path('create', ReportCreateView.as_view(), name='accountingreport_form'),
toot/templates/accounting_report/accountingreport_form.html {{ form }} 在模板呈现期间出错
<!DOCTYPE html>
<html>
<head lang="ja">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form method="post">
{% csrf_token %}
{{ form }}
<button type="submit">save</button>
</form>
</body>
</html>
设置.py
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'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',
],
},
},
]
解决方案
尝试将此添加到您的ReportCreateView
:
template_name = "accounting_report/accountingreport_form.html"
推荐阅读
- java - 来自变量的Dockerfile Spring Boot属性不起作用
- mongodb - Docker 无法运行入口点
- java - 如何在 JAVA 中将新属性添加到 XML 字符串中?条件:基于父密钥,如果我们需要进行解析或 SAX,我只能使用 JAVA 内部 api
- python - 如何在 Tensorflow 中删除张量中的重复值?
- swift - 快速将 UIImage 更改为数组或矩阵
- javascript - 为什么这个链接在粘贴到 url 栏中时有效,但在单击时无效?
- asp.net-core - datetimepicker 在 asp.net 核心中不起作用
- javascript - 为什么 Catch 不捕获错误?
- mysql - SQL Redshift 查询以选择每个组中的前 x 个日期
- matlab - Matlabs“splitapply”用于具有多个参数的函数