【问题标题】:Where are templates to django-filter package?django-filter 包的模板在哪里?
【发布时间】:2017-03-19 23:43:57
【问题描述】:

我有点困惑。

https://github.com/carltongibson/django-filter/blob/develop/django_filters/rest_framework/backends.py

从第 31 行到第 37 行 - 这是一个逻辑,如果我安装了脆皮,包应该使用 django_filters/rest_framework/crispy_form.html 文件。

我已经安装了所有最新的 django-filter 和crispy forms 包,但我的代码总是出错:

异常类型:TemplateDoesNotExist 异常值:

django_filters/rest_framework/crispy_form.html

您能解释一下我在哪里可以找到所有需要的模板吗?哪个回购?我在 django-filter repo 中没有看到这些文件,所以我有点迷茫。

【问题讨论】:

    标签: django-crispy-forms django-filter


    【解决方案1】:

    您可能需要将“django_filters”添加到 INSTALLED_APPS。我通过这样做解决了同样的问题。

    【讨论】:

      【解决方案2】:

      我已经安装了所有最新的 django-filter 和crispy forms 包...

      请检查这个。

      后端catches the missing template exception 所以你不应该看到那个错误。

      看不到模板文件的原因是the default templates are defined in the module,为了避免多余的文件和需要将Django Filter添加到INSTALLED_APPS。您可以通过在预期路径添加文件来覆盖这些。

      您看到的行为是出乎意料的,因此如果您可以将其减少到最小的可重现示例,请open an issue on GitHub

      look at the test case here — 这涵盖了确切的行为:

      如果模板路径不存在,请确保后端呈现默认值

      问题是,为什么这不适用于您的情况?

      【讨论】:

      • 我通过添加自己的后端类解决了这个问题。从 rest_framework_filters 导入后端类 CustomBackend(backends.DjangoFilterBackend): template = 'rest_framework/filters/django_filter.html'
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-20
      • 2020-12-02
      • 2016-10-27
      • 2013-05-23
      • 2013-08-13
      • 1970-01-01
      • 2014-12-30
      相关资源
      最近更新 更多