为什么 pdb.set_trace() 在 templatetag 定义中不起作用?

发布于 2025-01-04 12:41:20 字数 563 浏览 1 评论 0原文

我写了一个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() 插入 GetLoopF​​orm.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧伤慢歌 2025-01-11 12:41:20

由于它是模板标签,因此可能会在服务器启动时缓存。尝试重新启动服务器,应该可以解决问题。

Since it is a template tag, it might be cached on server start. Try to restart the server, that should solve the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文