I'm new to Django and I'm trying to add a basic sitemap.xml. I only have static pages. How do I add a simple sitemap.xml so that I can access it from http://mydomain.com/sitemap.xml
urls.py
pages
--- templates
---- pages
-- about.html
-- contact.html
-- etc...
--- views.py
In my urls.py file:
from django.conf.urls import patterns, include, url
from django.views.generic.base import TemplateView
from [myfolder].pages.views
from django.contrib import admin
from django.views.generic import RedirectView
urlpatterns = patterns('',
url(r'^$', TemplateView.as_view(template_name='pages/home.html'), name='home'),
url(r'^about/$', TemplateView.as_view(template_name='about.html')),
url(r'^sitemap\.xml/$', TemplateView.as_view(template_name='sitemap.xml')),????
)
How can I generate a sitemap based off the pages I have in templates/pages??
An alternative to the previous answers is to do a similar thing to adding the robots.txt file to your urls.py file.
from django.views.generic import TemplateView
urlpatterns = patterns('',
url(r'^sitemap\.xml$', TemplateView.as_view(template_name='sitemap.xml', content_type='text/xml')),
)
The only difference is to change the content_type value to text/xml where it would be text/plain for the robots.txt file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With