Django: Built in way to generate HTML sitemaps (not XML) -
we're using django sitemap framework generate search engine friendly xml sitemap. works fine. it's nice use , customize own needs.
i know rewrite template used xml sitemap or generate list of pages in our system normal db queries , alike, it's hard believe there not preconfigured solution such common problem.
i want same list used in our xml sitemap in normal (html) frontend view.
tl;dr:
what's best/default way build html sitemap intended people finding stuff on our site (instead of bots)?
you can embed xml generated sitemap processor in standard html
url(r'^sitemap/','django.contrib.sitemaps.views.sitemap', \ {'sitemaps' : sitemaps, 'template_name' : '<yoursite>/usr_sitemap.html', 'mimetype' : 'none'}),
setting 'mimetype' none allow include html code in template used generation. produces html containing sitemap xml code. need style using css. sample template(usr_sitemap.html) be:
{% extends 'base.html' %} {% load staticfiles %} {% block content %} << content section of base.html <?xml version="1.0" encoding="utf-8" type='text/css' href='{% static '<yoursite>/your_css.css' %}'?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"> {% spaceless %} {% url in urlset %} <url> <loc>{{ url.location }}</loc> {% if url.lastmod %}<lastmod>{{ url.lastmod|date:"y-m-d" }}</lastmod>{% endif %} {% if url.changefreq %}<changefreq>{{ url.changefreq }}</changefreq>{% endif %} {% if url.priority %}<priority>{{ url.priority }}</priority>{% endif %} <news:news> <news:tag1> blabla </news:tag1> <news:tag2> blabla </news:tag2> </news:news> </url> {% endfor %} {% endspaceless %} </urlset> {% endblock %}
Comments
Post a Comment