First of all - that is not how a context processor works. You are confusing template tags and context processors. A template tag is one of the following: https://docs.djangoproject.com/en/2.0/howto/custom-template-tags/
It must then be registered and then included in your template. So then you should put it in the templatetags module and load it into your template. It should NOT be added to the OPTIONS dictionary. However, a context processor is called EVERYTIME a request is handled and returns it's content to the template - WITHOUT the need of calling anything OR adding it to your template. So in your case you would need to move the context processor from the templatetags module, not load it with register, and also load use {% include %} in your template. And finally don't call it. What happens with the context processor is that it autmatically gets called and the dictionary result is added to the context of the template. So your context processor should look like this: def GetItemDictionary(request): # 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' }, } Without registering it or anything. This way you will be able to get the information in your template like this: {% block sidebar %} <ul> <li><a href="{{ year.urlname }}">{{year.readable}}</a> <li><a href="{{ region.urlname }}">{{region.readable}}</a> <li><a href="{{ location.urlname }}">{{location.readable}}</a> </ul> {% endblock %} The reason for needing to add year, region and location, is because that is the way you are creating the dictionary in your context processor. Best regards, Andréas 2018-06-18 21:16 GMT+02:00 Mikkel Kromann <mik...@aabenhuskromann.dk>: > 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 > <https://groups.google.com/d/msgid/django-users/54694b80-86ae-4934-913f-7a03e215463e%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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/CAK4qSCdaK3umObaOcrQ3%3DzyMzoo_5S2Y4kVJCKfK_wP6hiWOiA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.