account / list_of_post_by_subactegory.html TemplateDoesNotExist

时间:2018-09-16 10:28:55

标签: python django

我不能解决这个问题。当您尝试加载页面时, list_of_post_by_subcategory.html 会抛出TileOverlay,请帮忙。

models.py

(Map.getProjection().getVisibleRegion())

urls.py

TemplatesDoesNotExist

views.py

class Category(models.Model):
    category = models.CharField(max_length=250)
    slug = models.SlugField()

    def __str__(self):
        return self.category

    def get_absolute_url(self):
        return reverse('list_of_post_by_category', args=[self.slug])

class SubCategory(models.Model):
    category = models.ForeignKey(Category, on_delete=models.SET_NULL, null=True, blank=True, related_name="subcategories")
    subcategory = models.CharField(max_length=250)
    slug = models.SlugField()

    def __str__(self):
        return self.subcategory

    def get_absolute_url(self):
        return reverse('list_of_post_by_subcategory', args=[self.slug])

list_of_post_by_subcategory.html

url(r'^category/(?P<slug>[-\w]+)/$', views.list_of_post_by_category, name= 'list_of_post_by_category'),
url(r'^subcategory/(?P<slug>[-\w]+)/$', views.list_of_post_by_subcategory, name= 'list_of_post_by_subcategory'), 

类似的模板 list_of_post_by_category.html 正确加载。但是 list_of_post_by_subcategory.html 会抛出def list_of_post_by_category(request, slug): categories = Category.objects.all() category=get_object_or_404(Category, slug = slug) subcategories = SubCategory.objects.filter(category=category) posts = Post.objects.filter(category=category) return render(request, "account/list_of_post_by_category.html", {'categories': categories, 'posts': posts, 'category': category, 'subcategories': subcategories}) def list_of_post_by_subcategory(request, slug): subcategory=get_object_or_404(SubCategory, slug=slug) posts = Post.objects.filter(subcategory=subcategory) return render(request, "account/list_of_post_by_subcategory.html", {'posts': posts, 'subcategory': subcategory})

1 个答案:

答案 0 :(得分:1)

文件名在这里不匹配。您将错误发布为account/list_of_post_by_subactegory.html TemplateDoesNotExist。请查看您提到的html文件的名称(子对象)。而您呼叫的那个人的名字是account/list_of_post_by_subcategory.html