本文介绍了包含模板标签在django中不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Views.py文件如下所示

My Views.py files looks like below

  def homepage(request):
      template = 'homepage.html'
      list_display_template = 'list.html'
      list = model.objects.all()

      return render_to_response(template,
           {'list_display_template': list_display_template,
            'list' : list,},
            context_instance=RequestContext(request))

而我的homepage.html如下所示: -

And my homepage.html looks like below:-

  {% extends "base.html" %}

  {% block main_content %}
      {% include list_display_template %}
  {% endblock %}

我的list_display_template(list.html)具有以下信息

And my list_display_template (list.html) has following information

  < div class= "span10">
     {% for item in list %}
         <p> {{ item }}</p>
      {% endfor %}
  </div>

上面的开发工作正常,但在生产中,包含标签不工作,当我检查元素,它没有显示任何来自list.html的项目。有人可以帮助这个。

The above works fine in development, but in production the include tag is not working and when i inspect the element, it is not showing any items from list.html. could someone help with this.

编辑: - 我的文件夹结构如下

Edit :- My folder structure is as below

project_name/
    project_name/
         settings.py
    static/
       css/
       images/
    templates/
      homepage.html
      list.html
      base.html

谢谢

推荐答案

我有同样的问题,但我会以类似问题的其他用户可以理解的方式回答这个问题。

I had the same problem,but i will answer this question in a way that other users with a similar problem can understand.

你可能在包含的html文件中有一个模板块,
这个块或者是期待某种类型的包含,或者是导致一个错误,它正在调用异常django通过,因此您无法看到错误,
如果您在父模板中使用 {%load someLoad%} 然后在包含的html中使用它,
i猜测这个版本从版本变化。

you probably have a template block of some kind in the included html file,this block either is expecting an include of some kind or is causing an error of which is calling exception that django passes and therefore you are not able to see the error,if you use {% load someLoad %} in the parent template then use it in the included html too,i guess this changes from version to version.

在我的(非常具体)的情况下,我在包含的html文件中缺少这个:

in my (very specific) case i had this missing in the included html file:

{% load i18n %}
{% load cms_tags sekizai_tags %}

这篇关于包含模板标签在django中不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 02:32
查看更多