1

I have a base.html in my_project/jinja2/ and it contains everything except the <body> for a site. We then extend base.html as one does.

In this example I am extending base.html from app people in a file at my_project/people/jinja2/people/people_list.html using something like this:

{% extends "base.html" %}

{% block content %}
<!-- Some html -->
{% endblock content %}

My base.html includes a link to the blog rss feed in the <head> like so:

<link rel="alternate" type="application/atom+xml" title="Blog" href="{{ url('blog:articles_feed') }}" />

This works fine most places such as my_project/jinja2/index.html and my_project/jinja2/blog_list.html but in this 3rd app people, I am getting the following error at this same line of template code:

AttributeError: 'str' object has no attribute '__call__'

Since jinja2 has better debugging I can run python in werkzueg and see some potential details of what might be happening:

locals()

which outputs:

{
    '_': {...},
    'static': < bound method StaticFilesStorage.url of < django.contrib.staticfiles.storage.StaticFilesStorage object at 0x7f423ec3ebe0 >> ,
    'joiner': < class 'jinja2.utils.Joiner' > ,
    'request': < WSGIRequest: GET '/case-studies/hog?__debugger__=yes&cmd=locals()&frm=139922493301984&s=XfAagGnpxRWFBRRd0Uzk' > ,
    'page': None,
    'csrf_input': < django.utils.functional.lazy. < locals > .__proxy__ object at 0x7f423e8262e8 > ,
    'cycler': < class 'jinja2.utils.Cycler' > ,
    'dict': < class 'dict' > ,
    'absolute_url': < function absolute_url at 0x7f423ece5b70 > ,
    'lipsum': < function generate_lorem_ipsum at 0x7f423ebfc8c8 > ,
    'view': < leaf.views.LeafTemplateView object at 0x7f423e820198 > ,
    'range': < class 'range' > ,
    'ngettext': < function ungettext at 0x7f42450547b8 > ,
    'gettext': < function ugettext at 0x7f4245054730 > ,
    'absolute_root': < function absolute_root at 0x7f423ece8268 > ,
    'datetime': < class 'datetime.datetime' > ,
    'csrf_token': < django.utils.functional.lazy. < locals > .__proxy__ object at 0x7f423e826400 > ,
    'url': 'people/all'
}

I'm not sure if this is a correct assumption, but is url not being correctly added to the environment as a function, but a string instead? It's in my jinja2.py file, and works elsewhere as expected in jinja2 templates. What gives?

2
  • 1
    You might be passing a context variable also called url in your people view. Commented Apr 7, 2016 at 3:22
  • Interesting point. I hadn't considered something like this. I set this up in the people app with a url route like: url(r'^people-list/', TemplateView.as_view(template_name="people_list.html")),. From Django source for TemplateView, I don't see TemplateView adding a url context variable. Using jinja, would anything else be adding context unexpectedly for just this view (it works fine in some other views). Commented Apr 7, 2016 at 14:48

1 Answer 1

1

Selcuk had the right idea. I was using jinja templates, and the kwargs are added in automatically. One of my kwargs was <url> and was over-riding the url extension I had added to the jinja environment. Renaming the kwarg to something else solved the issue.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.