0

我正在获取“blog_splash”的所有链接,这很好。除了这些链接之外,我还需要在 sitemap.xml 中生成主页和关于链接。

sitemaps.py 如下

from django.contrib.sitemaps import Sitemap
from .models import DbPost
 
 
class BlogPostSitemap(Sitemap):
    changefreq = "weekly"
    priority = 0.8
    protocol = 'https'

    def items(self):
        return DbPost.objects.all()

    def lastmod(self, obj):
        return obj.date
        
    def location(self,obj):
        return '/blog_splash/%s' % (obj.id)

urls.py 如下:

urlpatterns = [
        path('sitemap.xml', sitemap, {'sitemaps': sitemaps}, name='django.contrib.sitemaps.views.sitemap'),
        path('', MainView.as_view(), name="home"),
        path('about', AboutView.as_view(), name="about"),
        path('blog_splash/<int:pk>', BlogSplashView.as_view(), name="blog_splash"),
]
4

0 回答 0