2

I'm making a website with django and rest framework and I found myself copying and pasting a lot of the same code on every page. I learned about creating a base.html and adding {% extends 'app/base.html' %} from http://tutorial.djangogirls.org/en/template_extending/. This worked great for most of my pages but I am having issues with 2 pages that have different forms (but I get the same error for all the forms). The error is:

TemplateSyntaxError at /boards/: Invalid filter: 'attr'

error during template rendering in template boards.html, error at line 30

I am confused because when I get rid of the {% extends 'app/base.html' %} and just copy the head of base.html into this other page, it works fine. The headers of the 2 are identical but something within the forms breaks when I try to use the base template. Its kind of a lot of code to include so I'm not going to include it unless requested. But hopefully someone has an idea of what the issue could be without seeing my code?

I guess it may be relevant to include that I am using django-widget-tweaks with my forms. I'm not sure if that is at all related to the problem.

Community
  • 1
  • 1
Catherine
  • 241
  • 1
  • 2
  • 15
  • please post the full error and please format your answer to separate the commentry from the code – e4c5 Jun 22 '16 at 00:15

1 Answers1

2

Turns out the issue was actually with django-widget-tweaks! I had {% load i18n widget_tweaks %} only in base.html but I also had to add it to the individual pages (I am still not really sure why, but it worked). So each template that extends base.html and that has a form on it looks like:

{% extends 'app/base.html' %}
{% load i18n widget_tweaks %}
{% block content %}
    ....
{% endblock %}

Apparently just loading widget tweaks in the base doesn't cut it, see the comments for why not.

Catherine
  • 241
  • 1
  • 2
  • 15
  • Did your local `{% block content %}` use `widget_tweaks`? – rrauenza Jun 22 '16 at 18:28
  • @rrauenza what do you mean by local block content? – Catherine Jun 22 '16 at 20:29
  • In the actual file you had to add `{% load i18n widget_tweaks %}`, were you using calls `widget_tweaks`? If so, that is consistent with django -- `extends` doesn't extend `load`'s. – rrauenza Jun 22 '16 at 20:31
  • http://stackoverflow.com/questions/9647126/using-a-django-template-tag-on-pages-that-extend-from-the-view-that-loads-the-ta – rrauenza Jun 22 '16 at 20:41
  • Oh yes, I added `{% load i18n widget_tweaks %}` to each html file that has a form in it. I did not know that extending the base template did not extend `load`'s, thanks for pointing that out! @rrauenza – Catherine Jun 22 '16 at 20:50