Code

Opened 3 years ago

Closed 14 months ago

#16829 closed New feature (fixed)

sitemap for static views

Reported by: madisv Owned by: zsiciarz
Component: Documentation Version: master
Severity: Normal Keywords: views sitemap
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

People also use static views which are not FlatPages. So it's a problem creating a sitemap for such urls.
This is not hard to do if you know how so should this code maybe also be in django or might we just document this so people would know how to do this.

Problem explained also:
http://stackoverflow.com/questions/4836188/django-sitemaps-and-normal-views

Solution by Matt Austin:
from django.core.urlresolvers import reverse
from django.contrib.sitemaps import Sitemap

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

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


sitemaps = {'views': ViewSitemap, 'news_articles': ArticleSitemap}

Attachments (0)

Change History (9)

comment:1 Changed 3 years ago by carljm

  • Component changed from contrib.sitemaps to Documentation
  • Has patch unset
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

I don't think this code needs to be in Django, but the sitemaps documentation could benefit from an example like this showing how to add static views to a sitemap.

comment:2 Changed 3 years ago by jacob

  • milestone 1.4 deleted

Milestone 1.4 deleted

comment:3 Changed 20 months ago by camilonova

This is a real issue, and i agree with carljm, if you suggest me a place for adding the documentation i can do that.

comment:4 Changed 14 months ago by zsiciarz

  • Owner changed from nobody to zsiciarz
  • Status changed from new to assigned
  • Version changed from 1.3 to master

comment:5 Changed 14 months ago by zsiciarz

comment:6 Changed 14 months ago by zsiciarz

  • Has patch set

comment:7 Changed 14 months ago by pyriku

  • Triage Stage changed from Accepted to Ready for checkin

Looks OK to me

comment:8 Changed 14 months ago by Zbigniew Siciarz <antyqjon@…>

In d77082b43877b4df0f29fa977b73b7b4feab84d4:

Added example of using sitemaps with static views.

References #16829.

comment:9 Changed 14 months ago by timo

  • Resolution set to fixed
  • Status changed from assigned to closed

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.