Finally solved the flatpage error of Django sitemap.

Source: Internet
Author: User

Many people know that Django provides the sitemaps function, that is, displaying website-related projects in sitemap. xml:

 

Generally, add the following method to URLs. py:

From Django. contrib. sitemaps import flatpagesitemap, genericsitemap

From ddtcms. Blog. sitemaps import blogsitemap
From ddtcms. Blog. Models import entry

 

Info_dict = {
'Queryset': entry. Objects. All (),
'Date _ field': 'pub _ date ',
}

Sitemaps = {
'Flatpags': flatpagesitemap,
'Blog ': blogsitemap,
}

Add the following to urlpatterns:

(R '^ sitemap. xml $', 'django. contrib. sitemaps. Views. sitemap', {'sitemaps ': sitemaps }),
# (R '^ sitemap. xml $', 'django. contrib. sitemaps. Views. Index', {'sitemaps ': sitemaps }),
(R' ^ sitemap -(? P <section>. +). xml $ ', 'django. contrib. sitemaps. Views. sitemap', {'sitemaps': sitemaps }),

 

Then access http: // 127.0.0.1: 8000/sitemap. XML in the browser.

 

I did it according to the above practice, but the following error may occur:

Attributeerror at/sitemap. xml
'Site' object has no attribute 'flatpage_set'

Request Method: Get
Request URL: Http: // localhost/sitemap. xml
Exception type: Attributeerror
Exception value:
'Site' object has no attribute 'flatpage_set'
Exception location: C:/python25/lib/Site-packages/Django/contrib/sitemaps/_ init _. py in items, line 81

 

This is about 'site 'object has no attribute 'flatpage _ set'. After reading the Django source code, I don't know what is going on.

 

Later, I checked some Django apps on Google and finally solved the above error.

The method is:

 

Add

Installed_apps = (
'Django. contrib. auth ',
'Django. contrib. Sites ',
'Django. contrib. contenttypes ',
'Django. contrib. session ',
......
'Django. contrib. flatpage', <add this

 

 

Middleware_classes = (

....
'Django. contrib. flatpages. Middleware. flatpagefallbackmiddleware ', <add this

 

 

Re-AccessHttp: // MAID: 8000/sitemap. xmlTry? The entry of sitemap defined in the blog module is displayed.

It's easy, isn't it?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.