Why is pdb.set_trace() not working in a templatetag definition?
-
28-04-2021 - |
質問
I have written a templatetag to solve the repetitive creation of a special form. Got some problems with the logic, so i inserted pdb.set_trace() to get to its roots. But strangely this set_trace() never seems to be executed when i call the templatetag. The tag looks like this:
@register.tag('get_loop_form')
def get_loop_form(parser,token):
import pdb;pdb.set_trace()
#put some logic here
return GetLoopForm()
And i simply call it in the template like this:
{% get_loop_form %}
Usually i get the chance to interact with the script at the line of the set_trace() when i do that. When i insert the set_trace() into the GetLoopForm.render method it works, but not when i insert it into get_loop_form. Why not?
edit: restarted the Django development server manually, which resulted in the code above working. I still do not understand why this happened.
解決
Since it is a template tag, it might be cached on server start. Try to restart the server, that should solve the problem.