Hi.

Once again thanks for all your invaluable advice to me so far. Now, I'm 
battling context_processors.
I really struggle to find a good example that can help me understand how to 
use them.
They seem quite helpful to a lot of stuff I plan to do.

I think I got the configuration in settings.py and @register right as my tag is 
accepted as registered.
What baffles me is whether to include "request" as argument to my context 
processor GetItemDictionary() 
The error I get now (without declaring request as an argument) is 

"GetItemDictionary() takes 0 positional arguments but 1 was given"


With request as argumetn to GetItemDictionary(request) I get this error:

'GetItemDictionary' did not receive value(s) for the argument(s): 'request'


Should I pass request to my GetItemDictionary somewhere in my view, or is 
that done automagically by the template?
I realise that I've probably done something wrong elsewhere, but I'm at a 
loss to guess where ...
I suspect that the @register.simple_tag stuff I do may be the culprit as 
the tag may not be simple.


thanks, Mikkel

>From project/app/templatetags/items_extra.py
from django import template
register = template.Library() 

@register.simple_tag()
def GetItemDictionary():
# For now pass a hardcoded dictionary - replace with query later
    return {
        'year': {'name': 'year', 'readable': 'Year', 'urlname': 'year_list' 
},
        'region': {'name': 'region', 'readable': 'Region', 'urlname': 
'region_list' }, 
        'location': {'name': 'location', 'readable': 'Location', 'urlname': 
'location_list' },
    }


>From my settings.py
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            BASE_DIR + '/templates/',
        ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'items.templatetags.items_extra.GetItemDictionary',
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
            'libraries':{
                'items_extra': 'items.templatetags.items_extra',
            },
        },
    },
]


>From my template:
{% load items_extra  %}
{% GetItemDictionary as Items %}
{% block sidebar %}
<ul>
{% for item in Items %}
    <li><a href="{% url item.urlname}">item.readable</a>
{% endfor %}
</ul>
I: {{ Items }}
{% endblock %}





-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/54694b80-86ae-4934-913f-7a03e215463e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to