Django Template Tag With No Arguments

django, templates

Solution

I think you need to add

return color_data

To the end of your function...

Problem

I have a template tag that returns a random hex color. I have tested this out and the code returns the color correctly. However when I load the templatetag in my template and call it it returns a value of 'None'. I have read the django documentation on template tags, and stackoverflow questions regarding this topic but can't find an answer for this situation. I'm sure it is very simple, and feel the problem is coming from a misunderstanding of how arguments are being passed into the function. Any help, even just a point to some relevant documentation I may be missing would be much appreciated. ``` from django import template import random register = template.Library() @register.simple_tag def random_color(): r = lambda: random.randint(0,255) color_data = '#%02X%02X%02X' % (r(),r(),r()) ```

Original source