i'm learning django , have problems templates.
i'm trying add content extended template.
structure of code:
base.html category -- category_detail.html -- list_content.html
category_detail.html
{% extends 'base.html' %} {% block title %} {{ category_name }} {% endblock %} {% block description %} {{ category_description }} {% endblock %} {% block content %} <div class="col-md-10 text-center"> <a href="{% url 'charts:category_error_list' category_name %}" id="list-button" class="btn btn-success btn-lg active" role="button" aria-pressed="true">error list</a> </div> {% endblock %}
simple subpage button. button should redirect template, hovewer gives me noreversematch.
list_content.html (which category_error_list defined in view)
{% extends 'category/category_detail.html' %} {% block content %} {{ block.super }} <h1 class="page-header"> string</h1> {% endblock %}
what i'm trying achieve displaying "some string" under button. (i know should done better ajax example, want learn basics).
urls.py
urlpatterns = [ url(r'^category/$', views.categories_list, name='categories'), url(r'^category/(?p<category_name>\w+)/$', views.category_detail, name='category_detail'), url(r'^category/(?p<category_name>\w+)/list/$', views.category_error_list, name='category_error_list'), ]
views.py
# ${url}/category/${category} def category_detail(request, category_name): cat_detail = category.objects.get(name=category_name) return render(request, 'charts/category/category_detail.html', {'category_name': cat_detail.name, 'category_description': cat_detail.description}) #${url}/category/${category}/list def category_error_list(request, category_name): category_with_errors = category.objects.filter(name=category_name) error_list = error.objects.get(category=category_with_errors) return render(request, 'charts/category/list_content.html', {'errors_list': error_list})
problems seems related urls.py
, can't find wrong.
stacktrace:
template error: in template /usr/src/app/analizer/charts/templates/charts/category/list_content.html, error @ line 0 reverse 'category_error_list' arguments '('',)' , keyword arguments '{}' not found. 1 pattern(s) tried: ['category/(?p<category_name>\\w+)/list/$'] 1 : {% extends 'category/category_detail.html' %} 2 : 3 : {% block content %} 4 : {{ block.super }} 5 : <h1 class="page-header"> cos tam </h1> 6 : {% endblock %} 7 : 8 :
if remove block.super
tag working, i'm overriding content on parent template. i'm doing wrong?
i'm using django-1.9.4.
i have found solution - nonintuitive me - working.
view category_error_list
missing category_name
variable, have fixed this:
def category_error_list(request, category_name): category_with_errors = category.objects.get(name=category_name) error_list = error.objects.get(category=category_with_errors) return render(request, 'charts/category/list_content.html', {'category_name': category_with_errors.name, 'errors_list': error_list})
Comments
Post a Comment