我想使用CreateView。 但是,它会生成错误django.template.exceptions.TemplateDoesNotExist:django / forms / widgets / text.html
root / 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/"
root / 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>
settings.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',
],
},
},
]
答案 0 :(得分:0)
尝试将其添加到您的@Nullable
:
ReportCreateView