формируется sitemap.xml

This commit is contained in:
Sergei Erjemin (Сергей Еремин) 2020-11-21 16:14:15 +03:00
parent 3de50d551a
commit 6c506ed251
5 changed files with 21 additions and 4 deletions

Binary file not shown.

View File

@ -26,6 +26,7 @@ urlpatterns = [
url(r'^$', views.index),
url(r'^(?P<dq_id>\d{1,12})_\S*$', views.by_id),
url(r'^sitemap.xml$', views.sitemap),
]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url><loc>https://dq.cube2.ru/</loc><priority>0.1</priority></url>{% for I in DATA %}
<url><loc>https://dq.cube2.ru/{{ I.ID }}_{{ I.SLUG }}</loc><priority>1</priority></url>{% endfor %}
</urlset>

View File

@ -33,7 +33,7 @@ def for_dq(dq):
tags = dq.tags.names()
tag_and_slug = []
for i in tags:
tag_and_slug.append({"name": i, "slug": pytils.translit.slugify(i.lower())[:128]})
tag_and_slug.append({"name": i, "slug": pytils.translit.slugify(i.lower())[:120]})
to_template.update({'TAGS': sorted(tag_and_slug, key=lambda x: x["name"])}) # tag_and_slug
if dq.kImages_id is None:
if len(tags) != 0:
@ -87,3 +87,14 @@ def index(request):
to_template.update({'ticks': float(time.process_time() - t_start)})
response = render(request, template, to_template)
return response
def sitemap(request):
template = "sitemap.xml" # шаблон
to_template = []
dq = TbDictumAndQuotes.objects.order_by('id').all()
for i in dq:
to_template.append({"ID": i.id,
"SLUG": pytils.translit.slugify(i.szContent.lower()[:120])})
response = render(request, template, {"DATA": to_template})
return response