формируется 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'^$', views.index),
url(r'^(?P<dq_id>\d{1,12})_\S*$', views.by_id), 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) urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

View File

@ -35,14 +35,14 @@
</td></tr><tr><td colspan="2">{% else %}</tr><tr><td>{% endif %} </td></tr><tr><td colspan="2">{% else %}</tr><tr><td>{% endif %}
<div class="tags"> <div class="tags">
{% for i in TAGS %}<a href="/?tag={{ i.slug }}">{{ i.name|safe }}</a> {% endfor %} {% for i in TAGS %}<a href="/?tag={{ i.slug }}">{{ i.name|safe }}</a> {% endfor %}
<div id="next"><a href="/{{ NEXT}}_{{ NEXT_TXT }}">&rightarrow;</a></div> <div id="next"><a href="/{{ NEXT }}_{{ NEXT_TXT }}">&rightarrow;</a></div>
</div> </div>
</td> </td>
</tr> </tr>
</table></center> </table></center>
<script type="text/javascript"> <script type="text/javascript">
setTimeout('location.replace("/{{ NEXT}}_{{ NEXT_TXT }}")', 15000); setTimeout('location.replace("/{{ NEXT }}_{{ NEXT_TXT }}")', 15000);
/*Изменить текущий адрес страницы через 3 секунды (3000 миллисекунд)*/ /*Изменить текущий адрес страницы через 3 секунды (3000 миллисекунд)*/
</script> </script>
<noscript> <noscript>

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() tags = dq.tags.names()
tag_and_slug = [] tag_and_slug = []
for i in tags: 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 to_template.update({'TAGS': sorted(tag_and_slug, key=lambda x: x["name"])}) # tag_and_slug
if dq.kImages_id is None: if dq.kImages_id is None:
if len(tags) != 0: if len(tags) != 0:
@ -52,7 +52,7 @@ def for_dq(dq):
return to_template return to_template
def by_id( request, dq_id): def by_id(request, dq_id):
t_start = time.process_time() t_start = time.process_time()
template = "index.html" # шаблон template = "index.html" # шаблон
dq = TbDictumAndQuotes.objects.get(id=dq_id) dq = TbDictumAndQuotes.objects.get(id=dq_id)
@ -87,3 +87,14 @@ def index(request):
to_template.update({'ticks': float(time.process_time() - t_start)}) to_template.update({'ticks': float(time.process_time() - t_start)})
response = render(request, template, to_template) response = render(request, template, to_template)
return response 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