B
B
blazer052016-01-27 14:08:35
Django
blazer05, 2016-01-27 14:08:35

How to correctly display the url in the template?

I get an error:
Reverse for 'goto' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
There is a function

def track_url(reguest):
    page_id = None
    url = '/rango/'
    if reguest.method == 'GET':
        if 'page_id' in reguest.GET:
            page_id = reguest.GET['page_id']
            try:
                page = Page.objects.get(id=page_id)
                page.views = page.views + 1
                page.save()
                url = page.url
            except:
                pass
    return redirect(url)

url
url(r'^goto/', views.track_url, name='track_url'),
output in template
{% if category %}
            {% if pages %}
            <ul>
                {% for page in pages %}
                    {% for tag in page.tags.all %}
                        <li><a href="{% url 'goto' %}?page_id={{page.id}}" target="_blank">{{ page.title }}</a></li>
                        Теги: <a href="{% url 'tags' tag.slug %}" target="_blank">{{ tag.title }}</a>
                    {%endfor %}
                {% endfor %}

If you directly write /rango/goto/ in the link, then it works. 'rango.views.track_url' also works, but I don't understand why 'goto' doesn't work like that, because there are no additional arguments in the request?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nerevar_soul, 2016-01-27
@blazer05

It is necessary to transfer the name or function to the url tag.
{% url 'track_url' %} or {% url 'app_name.views.track_url' %}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question