为什么 pdb.set_trace() 在 templatetag 定义中不起作用?
我写了一个templatetag来解决特殊表单的重复创建。逻辑上有一些问题,所以我插入了 pdb.set_trace() 来找到它的根源。但奇怪的是,当我调用 templatetag 时,这个 set_trace() 似乎从未被执行。标签看起来像这样:
@register.tag('get_loop_form')
def get_loop_form(parser,token):
import pdb;pdb.set_trace()
#put some logic here
return GetLoopForm()
我只是在模板中这样调用它:
{% get_loop_form %}
通常,当我这样做时,我有机会在 set_trace() 行与脚本进行交互。当我将 set_trace() 插入 GetLoopForm.render 方法时它可以工作,但当我将它插入 get_loop_form 时则不行。为什么不呢?
编辑:手动重新启动 Django 开发服务器,这导致上面的代码工作。我仍然不明白为什么会发生这种情况。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于它是模板标签,因此可能会在服务器启动时缓存。尝试重新启动服务器,应该可以解决问题。
Since it is a template tag, it might be cached on server start. Try to restart the server, that should solve the problem.