Friday, August 31, 2012

Re: How sitemaps used in the Django

Hi Mugdha,

First add 'django.contrib.sitemaps' to your installed apps.

Then create a file "sitemap.py" in your project root with something like....

****************
from django.core.urlresolvers import reverse
from django.contrib.sitemaps import Sitemap
from blog.models import Entry

class ViewSitemap(Sitemap):
    """Reverse static views for XML sitemap."""
    def items(self):
        # Return list of url names for views to include in sitemap
        return ['home']

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

class BlogSitemap(Sitemap):
    changefreq = "never"
    priority = 0.5

    def items(self):
        return Entry.objects.filter(status=1)

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


sitemaps = {'views': ViewSitemap,
                   'blog_posts': BlogSitemap,
                  }
*******************

in urls.py...
**********************
from project.sitemap import sitemaps
.....
url('^$', home, name='home'),
....etc...


On Friday, August 31, 2012 10:04:26 AM UTC+1, Mugdha wrote:
Please help me in generating site maps for app. which is in django.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/QOnbgyvZ9qAJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment