Answer the question
In order to leave comments, you need to log in
How to solve a problem in django in a blog?
url.py
url(r'^blog/(?P<slug>[-\W]+)/$', views.blog, name='blog'),
<div class="blog_section">
{% for blog in blogs%}
<h1>{{ blog }}</h1>
<p class="post_time">
<i class="fa fa-clock-o" aria-hidden="true"></i>
{{ blog.time }}
{% if request.user.is_authenticated %}
{% if request.user.is_admin %}
<a href="{% url 'main:editblog' %}"><i class="fa fa-pencil" aria-hidden="true"></i></a>
<a href=""><i class="fa fa-times" aria-hidden="true"></i></a>
{% endif%}
{% endif%}
</p>
<hr>
{{ blog.perex|safe}}
<a href="{% url 'main:blog/get_absolute_url' %}" class="whole_text">Полный текст
<i class="fa fa-angle-right" aria-hidden="true"></i></a>
{% endfor %}
</div>
def index(request):
return TemplateResponse(request, "main/index.html", {'blogs':Blog.objects.all()})
def blog(request, slug):
blog = get_object_or_404(Blog, slug = slug)
return TemplateResponse(request, "main/blog.html", {'blog': blog})
{% extends, "base.html" %}
{% block content %}
<h1>{{ blog }}<small>{{ blog.time }}</small></h1>
{{ blog.perex|safe }} <hr/>
{{ blog.content|safe }}
{% endblock %}
Answer the question
In order to leave comments, you need to log in
What is this crazy mess of designs ? The tag expects to receive the name of the url, that is, in your case , after which it returns the url. And the get_absolute_url method does the same. So you are trying to get the url from the blog object and pass it back to the url tag. What for? In addition, methods are not called through a slash. And yet, why do you have a comma in your template after the extends tag? {% url 'main:blog/get_absolute_url' %}
{% url %}
{% url 'main:blog' blog.slug %}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question