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"
'GetItemDictionary' did not receive value(s) for the argument(s): 'request'
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' },
}
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',
},
},
},
]
{% 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 %}
# For now pass a hardcoded dictionary - replace with query later
return {--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django...@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.
Best regards,Andréas
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@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/7d3981db-2b31-4c2a-a6fc-485cbdf44ef4%40googlegroups.com.
Well, you can access a dictionary like a list using these:
items.keys(), template:
for k in items.keys
items.values(), template:
for v in items.values
items.items(), template:
for k, v in items.items
Regards,
Andréas
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7d3981db-2b31-4c2a-a6fc-485cbdf44ef4%40googlegroups.com.
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...@googlegroups.com.
To post to this group, send email to
django...@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/CAK4qSCfaRS%3DYJVxx%3D%3Dp%3DVvUuhgzH6cpQENg1HNxz4Z7kXhneyA%40mail.gmail.com.
Regards,
Andréas
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@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/7d3981db-2b31-4c2a-a6fc-485cbdf44ef4%40googlegroups.com.
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+unsubscribe@googlegroups.com.
To post to this group, send email to django...@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/CAK4qSCfaRS%3DYJVxx%3D%3Dp%3DVvUuhgzH6cpQENg1HNxz4Z7kXhneyA%40mail.gmail.com.
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+unsubscribe@googlegroups.com.
To post to this group, send email to django...@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/f59370296c474c0faddbc07e27291e82%40ISS1.ISS.LOCAL.
def GetItemDictionary(request):
return {
'itemDictionary': [
{'name': 'region', 'readable': 'Region', 'urlname': 'region_list' },
{'name': 'location', 'readable': 'Location', 'urlname': 'location_list' },
]
}
{% for item in itemDictionary %}
<li><a href={% url item.urlname %}>{{ item.readable }}</a>
{% endfor %}
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
BASE_DIR + '/templates/',
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'items.contextprocessor.GetItemDictionary',
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
Regards,Andréas
Regards,
Andréas
To post to this group, send email to djang...@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/7d3981db-2b31-4c2a-a6fc-485cbdf44ef4%40googlegroups.com.
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...@googlegroups.com.
To post to this group, send email to djang...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK4qSCfaRS%3DYJVxx%3D%3Dp%3DVvUuhgzH6cpQENg1HNxz4Z7kXhneyA%40mail.gmail.com.
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.