2016-07-02 7 views
1

주기적으로 추가 및 제거되는 콘텐츠 용 동적 페이지가 포함 된 웹 사이트가 있습니다. 이와 함께 웹 사이트에는 /,/about, how-it-works 등과 같이 항상 존재하는 정적 페이지가 있습니다. 사이트 맵에 모든 동적 콘텐츠 페이지를로드하도록 sitemaps.py 파일을 구성했습니다.Django 사이트 맵 정적 페이지

sitemap.xml의

... 
<url> 
<loc> 
https://www.mywebsite.com/record?type=poem&id=165 
</loc> 
<changefreq>weekly</changefreq> 
<priority>0.5</priority> 
</url> 
... 

sitemaps.py

from django.contrib.sitemaps import Sitemap 

from website.models import Content 

class MySitemap(Sitemap): 
    changefreq = "weekly" 
    priority = 0.5 

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

models.py

class Content(models.Model): 
    content_type = models.CharField(max_length=255) 
    ... 
    def get_absolute_url(self): 
     return '/record?type=' + self.content_type + '&id=' + str(self.id) 

가 어떻게 tho를 추가하려면 정적 페이지 (/,/about 등) 내 사이트 맵에? 감사합니다.

답변

0

약간의 검색 후 나는 이걸 찾았습니다. Django Sitemaps and "normal" views. 매트 오스틴의 대답에 이어 나는 내가 원하는 것을 성취 할 수 있었다. 나는 내가 한 일을 떠날 것이고, 나중에 참조 할 수 있도록 여기에 남겨 둘 것이다.

sitemaps.py

from django.contrib.sitemaps import Sitemap 
from django.core.urlresolvers import reverse 

from website.models import Content 

class StaticSitemap(Sitemap): 
    """Reverse 'static' views for XML sitemap.""" 
    changefreq = "daily" 
    priority = 0.5 

    def items(self): 
     # Return list of url names for views to include in sitemap 
     return ['landing', 'about', 'how-it-works', 'choose'] 

    def location(self, item): 
     return reverse(item) 

class DynamicSitemap(Sitemap): 
    changefreq = "daily" 
    priority = 0.5 

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

urls.py

from website.sitemaps import StaticSitemap, DynamicSitemap 
sitemaps = {'static': StaticSitemap, 'dynamic': DynamicSitemap} 

urlpatterns = [ 
    ... 
    url(r'^sitemap.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps}), 
]