静态部分工作正常,但我的博客应用程序的动态帖子没有生成
from django.contrib.sitemaps import Sitemap
from django.urls import reverse
from .models import Post
class PostSitemap(Sitemap):
changefreq = "weekly"
priority = 0.9
def items(self):
return Post.objects.all()
我无法通过我的博客和模型中的 Post 类获得动态站点地图:
class Post(models.Model):
title=models.CharField(max_length=100)
header_image = models.ImageField(null=True , blank=True, upload_to="images/")
title_tag=models.CharField(max_length=100)
author= models.ForeignKey(User, on_delete=models.CASCADE)
body = RichTextUploadingField(extra_plugins=
['youtube', 'codesnippet'], external_plugin_resources= [('youtube','/static/ckeditor/youtube/','plugin.js'), ('codesnippet','/static/ckeditor/codesnippet/','plugin.js')])
#body = models.TextField()
post_date = models.DateTimeField(auto_now_add=True)
category = models.CharField(max_length=50, default='uncategorized')
snippet = models.CharField(max_length=200)
likes = models.ManyToManyField(User, blank=True, related_name='blog_posts')
def total_likes(self):
return self.likes.count()
class Meta:
verbose_name = "Entrada"
verbose_name_plural = "Entradas"
ordering = ['-post_date']
def __str__(self):
return self.title + ' | ' + str(self.author)
def get_absolute_url(self):
return reverse('home')
如果有人可以帮助我,我将不胜感激。网址.py:
from django.contrib.sitemaps.views import sitemap
from theblog.sitemaps import PostSitemap, StaticSitemap
sitemaps = {'static': StaticSitemap, 'blog': PostSitemap}