On Monday, 8 August 2011 16:51:52 UTC+1, Josh wrote:
>
> I'm trying to create custom templatetags now, while learning Django. When 
> an entry is displayed I want to list other entries with the same categories 
> below the entry. I also wrote a templatetag (following the Practical Django 
> Projects from James Bennet)
>
> I'm having problems with using a variable as input in a custom templatetag. 
> The custom templatetag is:
>
> {% get_related_entries weblog.entry 5 from {{object.categories}} as 
> related_entries %}
>      {% for entry in related_entries %}
>           <p><a href="{{ entry.get_absolute_url }}">{{ entry.title }}</a>
>      {% endfor %}
>
>
> <snip> 
>
 I'm stuck now at the following error and the debug-information says:
>

> *Caught ValueError while rendering: invalid literal for int() with base 
> 10: '{'*
>
>
> ../sandbox/lib/python2.6/site-packages/Django-1.3-py2.6.egg/django/db/models/fields/related.py
>  
> in _pk_trace
>         v = getattr(field, prep_func)(lookup_type, v, **kwargs) ...
> ../sandbox/lib/python2.6/site-packages/Django-1.3-py2.6.egg/django/db/models/fields/__init__.py
>  
> in get_prep_lookup
>             return self.get_prep_value(value) ...
> ../sandbox/lib/python2.6/site-packages/Django-1.3-py2.6.egg/django/db/models/fields/__init__.py
>  
> in get_prep_value
>         return int(value) ...
>
>
>
> It gets to the filter and gives an UTF error. The Postgres database is UTF8 
> and I also explicitly added the *# -*- coding: utf-8 -**- in the 
> django-file to be sure. I'm using Python 2.6.5 and Django 1.3
>
> I think I'm using the wrong approach with regard to the 
> {{object.categories}} in the customtag. What am I doing wrong and how can I 
> solve this? 
>
>
The problem is your use of the variable tag delimiters inside another tag. 
There's no reason for this: the general semantics of Django templatetags is 
that inside them, the syntax is Python-like. For example, you do `{% for 
category in object_categories %}`, not `{% for category in {{ 
object.categories }} %}`. So you should just refer to `object.categories` 
directly:

    {% get_related_entries weblog.entry 5 from object.categories as 
related_entries %}
--
DR.
 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/2TkWWzZUvhsJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to