开发者

django: Generating sitemap for multilingual sites

I've created a small article site. I am using, translema to store the same article in several languages (it creates copies of selected fields in the database, so they can be translated), How can I generate sitemaps in this case?

(Forget to say, that I am u开发者_运维百科sing localurl application, so my urls look like this http://site/en).


To generate sitemap per language you can use something like this:

from django.contrib.sitemaps import Sitemap
from pages.models import Page

class PageSitemap(Sitemap):
   priority = 0.5
   # this generates urls per language
   i18n = True

   def items(self):
     pages = Page.objects.filter(
        status=Page.PUBLISHED).order_by('-updated_at')
    return pages

   def lastmod(self, obj):
     return obj.updated_at


The sitemap app works by letting you write sitemap classes, that each have an items method. You simply have to construct one such class per language you have, and make sure you query only models with that specific language for each class. The documentation has a simple sitemap example to get you started.


not sure what the "translema" is but if you would use the Candy Translate instead it will be:

  • much faster (do not use DB)
  • will create the sitemap for you that will contain all language versions
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜