我尝试覆盖现有的站点地图模板以启用深层链接,但响应格式不在xml中。 的 urls.py
url(r'^sitemap\.xml$',sitemap,{'sitemaps':sitemaps,'template_name':'sitemaps/sitemap.xml','content_type':'application/xml'},name='django.contrib.sitemaps.views.sitemap')
sitemap.xml的
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
{% spaceless %}
{% for url in urlset %}
<url>
<loc>{{ url.location }}</loc>
<xhtml:link rel="alternate" href="android-app://{{ url.location }}" />
{% 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 %}
</url>
{% endfor %}
{% endspaceless %}
</urlset>
请帮助,我没有得到谷歌的解决方案。
答案 0 :(得分:0)
在命名空间定义的末尾添加/
为我工作。这是我使用标签的方式:
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml/">