• <bdo id='NQdej'></bdo><ul id='NQdej'></ul>
  1. <i id='NQdej'><tr id='NQdej'><dt id='NQdej'><q id='NQdej'><span id='NQdej'><b id='NQdej'><form id='NQdej'><ins id='NQdej'></ins><ul id='NQdej'></ul><sub id='NQdej'></sub></form><legend id='NQdej'></legend><bdo id='NQdej'><pre id='NQdej'><center id='NQdej'></center></pre></bdo></b><th id='NQdej'></th></span></q></dt></tr></i><div id='NQdej'><tfoot id='NQdej'></tfoot><dl id='NQdej'><fieldset id='NQdej'></fieldset></dl></div>

      <legend id='NQdej'><style id='NQdej'><dir id='NQdej'><q id='NQdej'></q></dir></style></legend>

    1. <tfoot id='NQdej'></tfoot>

      <small id='NQdej'></small><noframes id='NQdej'>

    2. Django 小部件模板覆盖不在项目模板目录中搜索.怎么修?

      时间:2023-09-03
      1. <legend id='iEWzB'><style id='iEWzB'><dir id='iEWzB'><q id='iEWzB'></q></dir></style></legend>

            <bdo id='iEWzB'></bdo><ul id='iEWzB'></ul>
                <tbody id='iEWzB'></tbody>
              <i id='iEWzB'><tr id='iEWzB'><dt id='iEWzB'><q id='iEWzB'><span id='iEWzB'><b id='iEWzB'><form id='iEWzB'><ins id='iEWzB'></ins><ul id='iEWzB'></ul><sub id='iEWzB'></sub></form><legend id='iEWzB'></legend><bdo id='iEWzB'><pre id='iEWzB'><center id='iEWzB'></center></pre></bdo></b><th id='iEWzB'></th></span></q></dt></tr></i><div id='iEWzB'><tfoot id='iEWzB'></tfoot><dl id='iEWzB'><fieldset id='iEWzB'></fieldset></dl></div>
              <tfoot id='iEWzB'></tfoot>

              <small id='iEWzB'></small><noframes id='iEWzB'>

              • 本文介绍了Django 小部件模板覆盖不在项目模板目录中搜索.怎么修?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试覆盖 Django 1.11 中的内置小部件模板.在这方面,我似乎正在做文档所说的所有事情,但是对于小部件模板,Django 根本没有查看我的项目,并且我收到了 TemplateDoesNotExist 错误.

                I am attempting to override a built in widget template in Django 1.11. I seem to be doing everything that the docs say to do in this regard, but for the widget templates, Django is not looking in my project at all, and I get a TemplateDoesNotExist error.

                这是我的覆盖:

                class MyFileWidget(widgets.FileInput):
                    template_name = 'myapp/my_file_widget.html'
                

                模板肯定在那里.如果我将模板传递给渲染调用,它会发现它很好.问题是路径问题.从视图调用渲染时,它会检查以下内容:

                The template is definitely there. If I pass the template to a render call, it finds it fine. Problem is an issue of paths. When calling render from a view, it checks the following:

                projectroot/templates/myapp/my_file_widget.htmldjangoroot/forms/templates/myapp/my_file_widget.html

                projectroot/templates/myapp/my_file_widget.html djangoroot/forms/templates/myapp/my_file_widget.html

                当它在我的项目中找到模板时,它会渲染它.当我在上面的类中提供模板路径时,这不会发生.在这种情况下,它不会签入我的项目模板,该文件实际存在的位置,并开始签入 django 路径,它不存在.因此出现错误消息.

                When it finds the template in my project, it renders it. This is NOT happening when I provide the template path in the class above. In that case, it does not check in my project templates, where the file actually exists, and begins checking in the django path, where it does not. Hence the error message.

                所以我不知道为什么加载器会在渲染调用时检查我的项目模板,但是在查找小部件覆盖的template_name"时却没有这样做.有什么想法吗?

                So I have no clue why this the loader would check my project templates on render calls, but then fail to do so when looking for the "template_name" of the widget override. Any ideas?

                推荐答案

                默认情况下,FORM_RENDERER 设置默认为 'django.forms.renderers.DjangoTemplates'.

                By default, the FORM_RENDERER setting defaults to 'django.forms.renderers.DjangoTemplates'.

                这会检查您应用的模板目录(例如 projectroot/myapp/templates/myapp/my_file_widget.html),但不会检查您项目的模板目录(例如 projectroot/templates/myapp/my_file_widget.html).

                This checks your apps' templates directory (e.g. projectroot/myapp/templates/myapp/my_file_widget.html), but it does not check your project's template directories (e.g. projectroot/templates/myapp/my_file_widget.html).

                如果您想使用与 TEMPLATES 设置相同的配置,则应使用 TemplatesSetting 渲染器.

                If you want to use the same configuration as your TEMPLATES setting, then you should use the TemplatesSetting renderer.

                FORM_RENDERER = 'django.forms.renderers.TemplatesSetting'
                

                您还需要更新您的 TEMPLATES 设置,以便 Django 仍然可以使用内置的小部件模板.最简单的方法是将 django.forms 添加到 INSTALLED_APPS.有关更多信息,请参阅文档.

                You will also need to update your TEMPLATES setting so that Django can still use the built in widget templates. The easiest way to do this is to add django.forms to INSTALLED_APPS. See the docs for more info about this.

                这篇关于Django 小部件模板覆盖不在项目模板目录中搜索.怎么修?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Matplotlib 更新滑块小部件范围 下一篇:如何对 Django Select 小部件中的选择进行分组?

                相关文章

                <i id='0idmo'><tr id='0idmo'><dt id='0idmo'><q id='0idmo'><span id='0idmo'><b id='0idmo'><form id='0idmo'><ins id='0idmo'></ins><ul id='0idmo'></ul><sub id='0idmo'></sub></form><legend id='0idmo'></legend><bdo id='0idmo'><pre id='0idmo'><center id='0idmo'></center></pre></bdo></b><th id='0idmo'></th></span></q></dt></tr></i><div id='0idmo'><tfoot id='0idmo'></tfoot><dl id='0idmo'><fieldset id='0idmo'></fieldset></dl></div>
              • <small id='0idmo'></small><noframes id='0idmo'>

                <tfoot id='0idmo'></tfoot>
                  <bdo id='0idmo'></bdo><ul id='0idmo'></ul>

                  1. <legend id='0idmo'><style id='0idmo'><dir id='0idmo'><q id='0idmo'></q></dir></style></legend>