Advertisement
Guest User

Django no reverse match for Blog Posts models

a guest
Apr 6th, 2020
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. #urls.py
  2. ---------------
  3. sitemaps = {
  4.     'static': StaticViewSitemap,
  5.     'blog': BlogSitemap,
  6. }
  7. urlpatterns = [
  8.     path('admin/', admin.site.urls),
  9.     path('i18n/', include('django.conf.urls.i18n')),
  10.     path('sitemap.xml', sitemap, {'sitemaps': sitemaps},name='django.contrib.sitemaps.views.sitemap'),
  11. ]
  12. -----------------
  13. #models.py
  14. -----------------
  15. blablabla typical Posts model with:
  16.    
  17. def get_absolute_url(self):
  18.         return reverse('blog:post', kwargs={'slug':self.slug})
  19. ------------------
  20. #sitemaps
  21. -----------------
  22.  
  23. class StaticViewSitemap(Sitemap):
  24.     priority = 0.5
  25.     changefreq = 'daily'
  26.     protocol = "https"
  27.  
  28.     def items(self):
  29.         return ['main:contact-us', 'main:homepage','blog:blog']
  30.  
  31.     def location(self, item):
  32.         return reverse(item)
  33.  
  34.  
  35. class BlogSitemap(Sitemap):
  36.     changfreq = "daily"
  37.     priority = 1.0
  38.  
  39.     def items(self):
  40.         return Post.objects.filter(status='p')
  41.  
  42.     def lastmod(self, obj):
  43.         return obj.published
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement