如何向 JavaScriptCatalog 视图添加断点?

How do I add a breakpoint to a JavaScriptCatalog view?

根据 the documentation for JavaScriptCatalog,我在我的一个 Django 应用程序中的 urlpatterns 添加了以下行:

from django.views.i18n import JavaScriptCatalog
from django.conf.urls import url

urlpatterns = [
    # ...
    url(r"^jsi18n/?", JavaScriptCatalog.as_view(), name="javascript-catalog"),
    # ...
]

但是如果我导航到 http:///localhost/jsi18n,我发现它不是 loading the catalog:

// ...
  /* gettext library */

  django.catalog = django.catalog || {};
  

  if (!django.jsi18n_initialized) {
// ...

我该如何调试呢?我怎样才能将 breakpoint() 插入到 JavaScriptCatalog.as_view() 值中以查看它在做什么以及它在寻找什么?

Subclass原来的class,在其__init__中放一个breakpoint(),然后调用super().__init__:

from django.views.i18n import JavaScriptCatalog
from django.conf.urls import url


class MyCatalog(JavaScriptCatalog):
    def __init__(self, *args, **kwargs):
        breakpoint()
        return super().__init__(*args, **kwargs)

urlpatterns = [
    # ...
    url(r"^jsi18n/?", MyCatalog.as_view(), name="javascript-catalog"),
    # ...
]

或者覆盖一些其他的方法,比如get_catalog:

class MyCatalog(JavaScriptCatalog):
    def get_catalog(self, *args, **kwargs):
        breakpoint()
        return super().get_catalog(*args, **kwargs)