Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
613 views
in Technique[技术] by (71.8m points)

include template tag not working in django

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))

And my homepage.html looks like below:-

  {% extends "base.html" %}

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

And my list_display_template (list.html) has following information

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

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

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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.

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...