{在django中扩展模板}在我的base.html中,django会自动将我的head标签的所有内容放入我的body标签中

时间:2014-05-14 17:23:24

标签: python django templates

我遇到了django模板的问题。

我的问题来了,因为当我在浏览器中显示我的网站时,django将我的head标签的所有内容放入我的body标签中。

这是我的base.html

<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="utf-8">
<title>SecureKids {% block title %}{{title}}{% endblock %}</title>
</head>
<body>
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">{% block apartado %} {% endblock %}</h1>
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
             <p class="text-success">{% block msg %}{% endblock %}</p>              
            <div class="row">
                    {% block contenido %}---{% endblock %}

            </div><!-- /.row -->


        </div><!-- /#page-wrapper -->
</body>
</html>

这是一个从base.html扩展的模板

{% extends "base.html" %}
{%load i18n%}
{% block apartado %}
{% trans 'Control Panel' %} <small>{% trans 'Device' %} {{device.name}}</small>
{% endblock %}
{% block contenido %}
<h2>{% trans 'WELLCOME' %}</h2>
<div>
<h3>{% trans 'Child:' %} <small>{{device.child.name}}</small></h3>
<h3>{% trans 'Father's device:' %} <small>{{device.name}}</small></h3>

</div>
{% endblock %}

这是我浏览器中的结果

<html lang="en">
<head>
</head>
<body>
"


"
<meta charset="utf-8">
<title>SecureKids </title>


    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">
                    Control Panel <small>Device</small>
                </h1>
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
             <p class="text-success"></p>               
            <div class="row">

                 <h2>WELLCOME</h2>
                 <div>
                   <h3>Child: <small>m</small></h3>
                   <h3>Father's device: <small>m disp</small></h3>

                </div>      
       </div><!-- /.row -->     
   </div><!-- /#page-wrapper -->
</body>
</html>
本例中的views.py中的

函数

@login_required
def panel(request,oid):


    device = get_object_or_404(Device,pk=oid,child__father=request.user.id)

    messages.add_message(request, messages.INFO,"Este dispositivo no existe")
    return HttpResponseRedirect('/')


    request.session["device"] = device.id
    request.session["devicen"] = device.name
    request.session["childn"] = device.child.name 
    return render_to_response('children/panel.html',{'device':device},context_instance=RequestContext(request))

正如您在我的浏览器中看到的,所有内容都在body标签中,django在body标签后面还包含3个空行

我希望有人可以帮助我 感谢

0 个答案:

没有答案