M
M
maestro072017-04-10 07:45:19
Django
maestro07, 2017-04-10 07:45:19

How to solve a problem in django in a blog?

url.py

url(r'^blog/(?P<slug>[-\W]+)/$', views.blog, name='blog'),

index.html
<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>

views.py
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})

blog.html
{% extends, "base.html" %}

{% block content %}
  <h1>{{ blog }}<small>{{ blog.time }}</small></h1>
  {{ blog.perex|safe }} <hr/>
  {{ blog.content|safe }}
{% endblock %}

Reverse for 'blog/get_absolute_url' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
When I add "Full Text" to open a blog, it shows this error

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2017-04-10
@sergey-gornostaev

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 question

Ask a Question

731 491 924 answers to any question