我在/poll/poll/result.html上收到此错误TemplateDoesNotExist。...我认为我指向的是poll / poll / result.html,但如何将其指向poll / result.html
if(SC_QT OR SC_IDE)
set(QT_COLLIDER_LANG_CLIENT ON)
include(../QtCollider/CMakeLists.txt)
list(APPEND sclang_sources ${QT_COLLIDER_SRCS})
endif()
我是django的新手,但我在这里可能做错了什么。这是template.html的文件结构:mysite / polls / templates / polls / template.html和result.html其mysite / polls / templates / polls / result.html
Views.py
{'Gender': <QuerySet [{'Gender': 'female', 'Diseases': 'Malaria', 'Number': 1}, {'Gender': 'female', 'Diseases': 'cholera', 'Number': 2}
urls.py
from django.views.generic import ListView, CreateView, UpdateView
from django.urls import reverse_lazy
from . models import MyModel
from . forms import MyModelForm
from django.db.models import Count
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponse, HttpResponseRedirect
from django.urls import reverse
from django.views.generic.list import ListView
class CreateMyModelView(CreateView):
model = MyModel
form_class = MyModelForm
template_name = 'poll/template.html'
success_url = 'poll/result.html'
class MyModelListView(ListView):
model = MyModel
def get_queryset(self):
queryset = MyModel.objects.values('Gender', 'Diseases').annotate(Number=Count("Gender"))
return render('poll/result.html', {'Gender': queryset})
models.py
from django.conf.urls import url
from django.urls import path
from . import views
urlpatterns = [
url(r'^$', views.CreateMyModelView.as_view(), name='abc'),
path('poll/result.html', views.MyModelListView.as_view(), name='result'),
]
result.html
from django.db import models
Gender = (
('male', 'MALE'),
('female', 'FEMALE'),
)
Diseases = (
('cholera', 'CHOLERA'),
('hiv', 'HIV'),
('Malaria', 'MALARIA'),
('Typhoid', 'TYPHOID'),
)
class MyModel(models.Model):
Gender = models.CharField(max_length=16, choices=Gender, default='MALE')
Diseases = models.CharField(max_length=16, choices=Diseases, default='MALARIA')
vote = models.IntegerField(default=0)
def __str__(self):
return self.Gender
def __str__(self):
return self.Diseases
答案 0 :(得分:0)
您的模板位于“ poll s /result.html”,但是您告诉视图它是“ poll / result.html”。
(请注意,您实际上不应该给URL路径以“ html”结尾;这没有必要,这会使您感到困惑。URL和模板位置彼此无关。)