django, gravatar - add_to_builtins('gravatar.gravatar') causes crash on page load

StackOverflow https://stackoverflow.com/questions/11149696

  •  16-06-2021
  •  | 
  •  

Question

add_to_builtins('gravatar.gravatar')

  • is being used in my settings.py file, and it causes a crash on page load with this error:

Traceback (most recent call last):

File "C:\development\python\Lib\site-packages\django\core\servers\basehttp.py", line 283, in run self.result = application(self.environ, self.start_response)

File "C:\development\python\Lib\site-packages\django\contrib\staticfiles\handlers.py", line 68, in call return self.application(environ, start_response)

File "C:\development\python\Lib\site-packages\django\core\handlers\wsgi.py", line 272, in call response = self.get_response(request)

File "C:\development\python\Lib\site-packages\django\core\handlers\base.py", line 169, in get_response response = self.handle_uncaught_exception(request, resolver, sys.exc_info())

File "C:\development\python\Lib\site-packages\django\core\handlers\base.py", line 203, in handle_uncaught_exception return debug.technical_500_response(request, *exc_info)

File "C:\development\python\Lib\site-packages\django\views\debug.py", line 59, in technical_500_response html = reporter.get_traceback_html()

File "C:\development\python\Lib\site-packages\django\views\debug.py", line 128, in get_traceback_html t = Template(TECHNICAL_500_TEMPLATE, name='Technical 500 template')

File "C:\development\python\Lib\site-packages\django\template\base.py", line 108, in init self.nodelist = compile_string(template_string, origin)

File "C:\development\python\Lib\site-packages\django\template\base.py", line 135, in compile_string parser = parser_class(lexer.tokenize())

File "C:\development\python\Lib\site-packages\django\template\debug.py", line 34, in init super(DebugParser, self).init(lexer)

File "C:\development\python\Lib\site-packages\django\template\base.py", line 208, in init print lib.tags

AttributeError: 'NoneType' object has no attribute 'tags'

If i don't have any issue with using gravatar if i don't use the add_to_builtins functionality - that is, with plain old load tags in my views. I'm just using it a fair bit, so thought i might make use of the add_to_builtins functionality.

From the looks of things, the imported version crashes because the import_library(module) for gravatar.gravatar returns None (i know this because i printed out that line, and it returns None) - what is wrong with what i've done?

Était-ce utile?

La solution

oh gravatar.

Ok, so i was all wrong in how to import this using the add_to_builtins - what i needed to do was:

add_to_builtins('gravatar.templatetags.gravatar')

i'm unsure as to why, but that works a treat. Now i don't need to have any messy "load" statements, and i can happily call

{% gravatar story.user 40 %}

from any of my templates. yay!

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top