第9行的块标记无效:'静态',预期'空'或者' endfor'。在Django Block

时间:2017-08-17 04:43:29

标签: django django-templates

我使用继承var html = "<input type='button' class='btn btn-sm btn-primary' value='Ok'" + "onclick='TaskFinishedRequestMode(" + data[i].TaskFinishedRequest + "," + data[i].EmpTaskAssignCompletionId + "," + data[i].RequestById + "," + data[i].TeamLead + ", \'" + data[i].Employee_Name + "\' , \'" + data[i].ProjectName + "\' )'/>" ; 的模板:

我将block复制到index.html

将块添加到主要内容中:

所以base.html是这样的:

base.html

<!DOCTYPE html> <html lang="zh-cn"> <head> <title>{{ data.info.winery_name }}</title> <meta charset="UTF-8"> {% load static %} <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="format-detection" content="telephone=no"> <meta name="renderer" content="webkit"> <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"> <meta http-equiv="Cache-Control" content="no-siteapp" /> <link rel="alternate icon" type="image/png" href="{% static 'images/favicon.png' %}"> <link rel='icon' href='favicon.ico' type='image/x-ico' /> <meta name="description" content="" /> <meta name="keywords" content="" /> <link rel="stylesheet" href="{% static 'css/default.min.css' %}" /> <!--[if (gte IE 9)|!(IE)]><!--> <script type="text/javascript" src="{% static 'lib/jquery/jquery.min.js' %}"></script> <!--<![endif]--> <!--[if lte IE 8 ]> <script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script> <script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script> <script src="{% static 'lib/amazeui/amazeui.ie8polyfill.min.js' %}"></script> <![endif]--> <script type="text/javascript" src="{% static 'lib/handlebars/handlebars.min.js' %}"></script> <script type="text/javascript" src="{% static 'lib/iscroll/iscroll-probe.js' %}" ></script> <script type="text/javascript" src="{% static 'lib/amazeui/amazeui.min.js' %}"></script> <script type="text/javascript" src="{% static 'lib/raty/jquery.raty.js' %} "></script> <script type="text/javascript" src="{% static 'js/main.min.js?t=1' %}"></script> </head> <body> <header> <div class="header-top"> <div class="width-center"> <div class="header-logo "><img src="{% static 'images/logo.png' %}" alt=""></div> <div class="header-title div-inline"> <strong>{{ data.info.winery_name }}</strong> <span>{{ data.info.winery_pinyin }}</span> </div> <div class="header-right"> <span>全国咨询热线</span> <span>{{ data.info.country_tel }}</span> </div> </div> </div> <div class="header-nav"> <button class="am-show-sm-only am-collapsed font f-btn" data-am-collapse="{target: '.header-nav'}">Menu <i class="am-icon-bars"></i></button> <nav> <ul class="header-nav-ul am-collapse am-in"> <li class="on"><a href="/index/" name="index">网站首页</a></li> <li><a href="/product/" name="show">经营酒类</a></li> <li><a href="/article_list/" name="new">酒类资讯</a></li> <li><a href="/about/" name="about">关于我们</a></li> <li><a href="/contact/" name="message">联系我们</a> <div class="secondary-menu"> <ul><li><a href="message.html" class="message"></a></li></ul> </div> </li> <li><a href="/message/" >留言订购</a></li> </ul> </nav> </div> </header> {% block main_content %} <div class="am-slider am-slider-default" data-am-flexslider="{playAfterPaused: 8000 , controlNav: false, directionNav: false }"> <ul class="am-slides"> {% for ban in data.banner %} <li><img src="{% static ban.img %}" alt="" ></li> {% endfor %} </ul> </div><div class="copyrights">Collect from <a href="http://www.cssmoban.com/" > </a></div> <main> <div class="index-only-small"> <ul> <li><a href="/about/"><span></span><p>关于我们</p></a></li> <li><a href="/productlist/"><span></span><p>经营酒类</p></a></li> <li><a href="/article_list/"><span></span><p>酒类资讯</p></a></li> <li><a href="/contact/"><span></span><p>联系我们</p></a></li> </ul> </div> <div class="index-main-title"> <p>关于我们</p> <span>{{ data.aboutus.profile }}</span> </div> <div class="index-main-body"> <ul> <li><img src="{% static data.aboutus.profile_image %}"><p>工艺专业</p></li> <li><img src="{% static 'images/ZHIJIAN.jpg' %}"><p>质检安全</p></li> <li><img src="{% static 'images/GANBEI.png' %}"><p>驰名广安</p></li> </ul> <p> {{ data.aboutus.profile_detail }} </p> <a href="/about/">了解更多</a> </div> <div class="index-sm-banner"> <img src="{% static 'images/smbanner.jpg' %}"> <p> {{ data.aboutus.profile_detail }} </p> <span></span> </div> <div class="index-main-bottom"> <p>经营酒类</p> <span>{{ data.aboutus.corebusiness_introduce }}</span> </div> <div class="project-case"> {% for wine in data.winery %} <div> <a href="/article_list/article_list_content-{{wine.id}}/"> <img src="{% static wine.img %}"> <div class="projec-case-right"> <h6>{{ wine.title }}</h6> <p>{{ wine.content }}</p> </div> </a> </div> {% endfor %} </div> </main> <div class="feature"> <img class="big" src="{% static 'images/main4.jpg' %}"> <img class="sm" src="{% static 'images/main5.jpg' %}"> </div> <main> <div class="index-main-hg-title"> <p>经营酒类</p> <span>{{ data.aboutus.corebusiness_introduce }}</span> </div> <div class="index-main-body"> <ul> {% for wine in data.winery %} <li><img style="width:300px; height:190px;" src="{% static wine.img %}"><p>{{ wine.title }}</p><span>{{ wine.price }}</span><a href="/productlist/productdetails-{{wine.id}}">MORE</a></li> {% endfor %} </ul> </div> <div class="news-info"> <h2>酒类资讯</h2> <div> <ul> {% for wine_con in data.winery_consult %} {% if forloop.counter0 == 0 %} <li class="news-left"><img src="{% static wine_con.img %}"><div><p>{{ wine_con.title }}</p><span>{{ wine_con.content }}</span><a href="/article_list/">MORE</a></div></li> {% else %} <li><img src="{% static wine_con.img %}"><div><p>{{ wine_con.title }}</p><span>{{ wine_con.content }}</span><a href="/article_list/">MORE</a></div></li> {% endif %} {% endfor %} </ul> </div> </div> <div style="clear:both"></div> <div class="news-dynamic"> <h2>酒类资讯</h2> <ul> {% for wine_con in data.winry_consult %} <li><a href="/article_list_content-{{win_con.id}}/"><p>{{ win_con.title }}</p><i class="font">&#xe6aa;</i><span>2017/06/01</span></a></li> {% endfor %} </ul> </div> </main> {% endblock main_content %} <footer class="footer"> <div class="footer-pc"> <ul> <li><p>网站首页 | 关于我们 | 工程案例 | 新闻资讯 | 联系我们</p></li> <li><p>地址:{{ data.info.address }}</p></li> <li><P>电话:{{ data.info.telphone }}</P></li> <li><p>邮编:{{ data.info.zipcode }}</p></li> <li><span>{{ data.info.theme }}</span></li> </ul> <img src="{% static 'images/qccode.png' %}" alt=""> </div> <div class="footer-phone"> <button data-am-smooth-scroll class="am-btn am-btn-success">Top<i class="font">&#xe611;</i></button> </div> </footer> </body> </html>

我只是主要内容:

index.html

当我在浏览器中访问{% extends 'base.html' %} {% block main_content %} <div class="am-slider am-slider-default" data-am-flexslider="{playAfterPaused: 8000 , controlNav: false, directionNav: false }"> <ul class="am-slides"> {% for ban in data.banner %} <li><img src="{% static ban.img %}" alt="" ></li> {% endfor %} </ul> </div><div class="copyrights">Collect from <a href="http://www.cssmoban.com/" > </a></div> <main> <div class="index-only-small"> <ul> <li><a href="/about/"><span></span><p>关于我们</p></a></li> <li><a href="/productlist/"><span></span><p>经营酒类</p></a></li> <li><a href="/article_list/"><span></span><p>酒类资讯</p></a></li> <li><a href="/contact/"><span></span><p>联系我们</p></a></li> </ul> </div> <div class="index-main-title"> <p>关于我们</p> <span>{{ data.aboutus.profile }}</span> </div> <div class="index-main-body"> <ul> <li><img src="{% static data.aboutus.profile_image %}"><p>工艺专业</p></li> <li><img src="{% static 'images/ZHIJIAN.jpg' %}"><p>质检安全</p></li> <li><img src="{% static 'images/GANBEI.png' %}"><p>驰名广安</p></li> </ul> <p> {{ data.aboutus.profile_detail }} </p> <a href="/about/">了解更多</a> </div> <div class="index-sm-banner"> <img src="{% static 'images/smbanner.jpg' %}"> <p> {{ data.aboutus.profile_detail }} </p> <span></span> </div> <div class="index-main-bottom"> <p>经营酒类</p> <span>{{ data.aboutus.corebusiness_introduce }}</span> </div> <div class="project-case"> {% for wine in data.winery %} <div> <a href="/article_list/article_list_content-{{wine.id}}/"> <img src="{% static wine.img %}"> <div class="projec-case-right"> <h6>{{ wine.title }}</h6> <p>{{ wine.content }}</p> </div> </a> </div> {% endfor %} </div> </main> <div class="feature"> <img class="big" src="{% static 'images/main4.jpg' %}"> <img class="sm" src="{% static 'images/main5.jpg' %}"> </div> <main> <div class="index-main-hg-title"> <p>经营酒类</p> <span>{{ data.aboutus.corebusiness_introduce }}</span> </div> <div class="index-main-body"> <ul> {% for wine in data.winery %} <li><img style="width:300px; height:190px;" src="{% static wine.img %}"><p>{{ wine.title }}</p><span>{{ wine.price }}</span><a href="/productlist/productdetails-{{wine.id}}">MORE</a></li> {% endfor %} </ul> </div> <div class="news-info"> <h2>酒类资讯</h2> <div> <ul> {% for wine_con in data.winery_consult %} {% if forloop.counter0 == 0 %} <li class="news-left"><img src="{% static wine_con.img %}"><div><p>{{ wine_con.title }}</p><span>{{ wine_con.content }}</span><a href="/article_list/">MORE</a></div></li> {% else %} <li><img src="{% static wine_con.img %}"><div><p>{{ wine_con.title }}</p><span>{{ wine_con.content }}</span><a href="/article_list/">MORE</a></div></li> {% endif %} {% endfor %} </ul> </div> </div> <div style="clear:both"></div> <div class="news-dynamic"> <h2>酒类资讯</h2> <ul> {% for wine_con in data.winry_consult %} <li><a href="/article_list_content-{{win_con.id}}/"><p>{{ win_con.title }}</p><i class="font">&#xe6aa;</i><span>2017/06/01</span></a></li> {% endfor %} </ul> </div> </main> {% endblock main_content %} 时,出现错误:

localhost:8000/index/

在浏览器回溯中,您可以看到我的代码包含endfor标记。

enter image description here

1 个答案:

答案 0 :(得分:0)

{% load static %}内必须index.html。请注意,任何{% load YYY %}都不是其他模板所固有的。必须在每个HTML模板中声明它。