Questions tagged [templatetags]

A template tag is a symbol within a template that does something. A template tag can produce content, serve as a control structure (an if statement or for loop), grab content from a database, or enable access to other template tags.

212 questions
87
votes
16 answers

Django 1.10.1 'my_templatetag' is not a registered tag library. Must be one of:

I want a menu thats custom depending which group you are member of. Im using Django 1.10.1, allauth and so on. When im trying to make my templatetag it fails and it says:¨ TemplateSyntaxError at / 'my_templatetag' is not a registered tag library.…
Sliljedal
  • 871
  • 1
  • 6
  • 3
9
votes
3 answers

Django registration of tag library not working

I try to register my custom template tag library in django, but unfortunately it isnt working! I want to create a custom include-tag and followed the instruction…
fredo.r
  • 361
  • 2
  • 12
8
votes
3 answers

python random.random() causes "'module' object is not callable" when used in custom template tag

If I start python from the command line and type: import random print "Random: " + str(random.random()) It prints me a random number (Expected, excellent). If I include the above-two lines in my django application's models.py and start my django…
Krystian Cybulski
  • 9,717
  • 9
  • 65
  • 94
8
votes
1 answer

translated enum fields in template tags

I try to show the name of an enum in the template.To be clear, I have enum like class in model.py class EmployerWorkerNumberRange(): R_0 = 0 R_1_5 = 1 R_6_15 = 2 UNKNOWN = 3 EMPLOYER_WORKER_NUMBER_RANGE =( (R_0,_("wnr_0")), (R_1_5…
brsbilgic
  • 10,643
  • 12
  • 55
  • 89
7
votes
1 answer

Handling request in django inclusion template tag

I am new to Django and am trying to put an upload file form into an inclusion tag. So I can use it in various templates. I have created the following inclusion tag: #upload_files.py @register.inclusion_tag('upload_form.html') def…
iali
  • 837
  • 1
  • 8
  • 21
6
votes
3 answers

Django: in template tag what does cl mean?

In django admin change list template there is a block: {% block result_list %} {% if action_form and actions_on_top and cl.show_admin_actions %}{% admin_actions %}{% endif %} {% result_list cl %} {% if action_form and…
dsalaj
  • 1,947
  • 3
  • 22
  • 36
5
votes
1 answer

How to mix Pug/Jade with Django conditionals and html element attributes?

I want to write Django conditionals for html attributes, like --- Content --- I am using pug/jade, so I can't put jade/pug…
Lu Chinke
  • 502
  • 5
  • 24
5
votes
1 answer

Mako templates using Django template tags

Our Django site is built using Mako templates. We want to use a third party project called django-socialregistration, but its template tags use Django's templates. If we used Django templates we could just {% load facebook_tags %} {%…
Dave Aaron Smith
  • 4,349
  • 29
  • 37
5
votes
4 answers

Django templatetag scope forcing me to do extra queries

The problem is that if I call a templatetag into a block and it fills me a variiable with the usual context[varname]=something, then if I need that variable into another block, I have to call the templatetag again. This for me means extra db…
Alex Rades
  • 79
  • 3
5
votes
2 answers

Django-Oscar override templatetags

I tried to override category_tags by creating a local version of catalogue application with a local templatetags folder which has a category_tags.py file (also init.py). It seems the default category_tags file is used. If I change the name of my…
Traian
  • 2,646
  • 22
  • 32
4
votes
2 answers

In Django, how can I iterate over the result of a custom template tag that requires arguments?

If I have created a template tag: @register.simple_tag def last_books(a_cat, cutoff=5): objects = Books.objects.filter(category=a_cat) return objects[:cutoff] How can I do something like this in my template: {% for book in last_books…
Steve
  • 43
  • 1
  • 3
4
votes
2 answers

Django TemplateTags not compiling

I am trying to create custom django templatetags for my project. I followed the guides available and created the tags. But the tags are not being picked up. They aren't even being compiled (as the .pyc file isn't generated). The structure is…
Gaurav Wadhwani
  • 1,312
  • 2
  • 14
  • 30
4
votes
1 answer

Django template tags with same name

For example I have 2 templatetags app1 templatetags app1_tags.py def custom_tag() app2 templatetags app2_tags.py def custom_tag() If I load in template both templatetags {% load…
Kamo Petrosyan
  • 202
  • 1
  • 8
4
votes
1 answer

For loop variable used in templatetag?

Trying to solve a problem with templatetags. I have two templatetags: @register.inclusion_tag('directory/_alphabet.html') def alphabet_list(names): """ Return a list of letters that last names start with. """ return { 'letters':…
kennethlove
  • 83
  • 1
  • 4
4
votes
1 answer

Django template get first?

I need to do something like {{ article.product.images.first.image.url }} In my template, but there is no "first" (images is a RelatedManager for which I found very little documentation). Is there another way to do this? I can get the first model…
mpen
  • 237,624
  • 230
  • 766
  • 1,119
1
2 3
14 15