Static Pages in a Django Website Frame

I have some doubts regarding the creation of sitemap.xml and the Django website framework.

Let's say I have a blog application that has post_detail pages with each content and a bunch of "auxiliary" pages, such as "view by tags", "view by author", etc.

  • Is it mandatory to include each page in the sitemap.xml file, including the helper pages? I want all the pages of the "helper" to be indexed, as there are a lot of keywords and text. I know that Sitemaps are designed to help index pages, provide some guidance to a web guru, but not restrict crawl. What is the best thing for? Include all or include only important pages?
  • If you have all the pages in the sitemap.xml file, then what is the way to send a simple, not saved on db-pages to sitemaps framework? One possible way is to have a sitemap class that returns return URLs by the name of the URL. But this, apparently, is not DRY, because I will have to register these url names for the second time (in the url () function and in the Sitemap class).

Perhaps I could have a django.conf.urls.defaults.url function for registering url-mapping for a Sitemap ... What do you think?

Thank.

+3
source share
1 answer

, . , , .

, django.contrib.sitemaps.Sitemap URL- . - :

class StaticSitemap(Sitemap):
    priority = 0.8
    lastmod = datetime.datetime.now()

    def __init__(self, filename):
        self._urls = []
        try:
            f = open(filename, 'rb')
        except:
            return

        tmp = []
        for x in f:
            x = re.sub(r"\s*#.*$", '', x) # strip comments
            if re.match('^\s*$', x):
                continue # ignore blank lines
            x = string.strip(x) # clean leading/trailing whitespace
            x = re.sub(' ', '%20', x) # convert spaces
            if not x.startswith('/'):
                x = '/' + x
            tmp.append(x)
        f.close()
        self._urls = tmp
    # __init__

    def items(self):
        return self._urls

    def location(self, obj):
        return obj

- Sitemap:

sitemap['static'] = StaticSitemap(settings.DIR_ROOT +'/sitemap.txt')

sitemap.txt :

# One URL per line.
# All paths start from root - i.e., with a leading /
# Blank lines are OK.

/tour/
/podcast_archive/
/related_sites/
/survey/
/youtube_videos/

/teachers/
/workshops/
/workshop_listing_info/

/aboutus/
/history/
/investment/
/business/
/contact/
/privacy_policy/
/graphic_specs/
/help_desk/
+3

Source: https://habr.com/ru/post/1751562/


All Articles