Wednesday, 15 February 2012

Django 1.5: When extending base.html, my tag displays in my child's -



Django 1.5: When extending base.html, my <head> tag displays in my child's <body> -

edit: adding total versions of base of operations , kid template.

i'm using django 1.5.8 , have base of operations template (in template root) , sub folders kid templates extend base.

when extend base.html contents of base of operations template show in body of kid template. happens on kid pages except index. there django template inheritance rule i'm not aware of?

here total base:

<!-- base.html --> <!doctype html> <html lang="en"> <head> {% load ganalytics %} {% load twitter_tag %} {% load compress %} {% load tags %} <meta charset="utf-8"> <!--<meta http-equiv="x-ua-compatible" content="ie=edge">--> <meta name="viewport" content="width=device-width, initial-scale=1"> {% block othermeta %} <meta name="description" content="welcome multimechanics"> <title>multimechanics</title> <link rel="icon" type="image/png" href="{{ static_url }}ico/favicon.ico" /> <!--needed salesforce--> <meta http-equiv="content-type" content="text/html; charset=utf-8"> {% endblock %} <!-- bootstrap core css --> <!--<link href="css/bootstrap.min.css" rel="stylesheet">--> {% compress css %} <link href="{{ static_url }}css/style.css" rel="stylesheet"> <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet"> <link href="{{ static_url }}css/animate.css" rel="stylesheet"> <link href="{{ static_url }}css/lightbox.css" rel="stylesheet"> <link href='http://fonts.googleapis.com/css?family=source+sans+pro:300,400,600,700' rel='stylesheet' type='text/css'> <link href='http://fonts.googleapis.com/css?family=ubuntu:300,400,500,700' rel='stylesheet' type='text/css'> {% endcompress %} {% ganalytics %} {% block otherheader %}{% endblock %} </head> <body> <!-- navigation --> <header> <div class="navbar navbar-default navbar-fixed-top" role="navigation"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> <span class="sr-only">toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="/"><img src="{{ static_url }}img/logo.png" alt="..."></a> </div> <div class="collapse navbar-collapse"> {% if user.is_authenticated %} <a href="/logout" class="navbar-btn btn btn-red pull-right hidden-sm hidden-xs">log out</a> {% else %} <a href="/login" class="navbar-btn btn btn-red pull-right hidden-sm hidden-xs">log in</a> {% endif %} <ul class="nav navbar-nav navbar-right"> <li class='dropdown {% active request "^/faqs/$" %} {% active request "^/multiscale/$" %} {% active request "^/about-us/$" %}'> <a href="#" class="dropdown-toggle" data-toggle="dropdown">about<b class="caret"></b></a> <ul class="dropdown-menu"> {% if request.get_full_path == "/" %} <li><a href="#about">product overview</a></li> <li><a href="#features">product applications</a></li> {% else %} <li><a href="/">multimech home</a></li> {% endif %} <li><a href="/about-us">multimech details</a></li> <li><a href="/multiscale">what's multiscale?</a></li> <!--<li><a href="/porfolio/demos">demos</a></li> <li><a href="/portfolio/case">case studies</a></li>--> <li><a href="/faqs">frequent questions</a></li> </ul> </li> <li class='dropdown {% active request "^/trueinnovation/$" %} {% active request "^/portfolio/$" %}'> <a href="/portfolio" class="dropdown-toggle" data-toggle="dropdown">showcases <b class="caret"></b></a> <ul class="dropdown-menu"> {% if request.get_full_path == "/" %} <li><a href="#showcases">featured demos</a></li> {% endif %} <li><a href="/portfolio">demo gallery</a></li> <li><a href="/trueinnovation">blog</a></li> </ul> </li> <li class='dropdown {% active request "^/careers/$" %} {% active request "^/contact-us/$" %} {% active request "^/login/$" %} {% active request "^/help/$" %} {% active request "^/register/$" %} {% active request "^/thanks/$" %}'> <a href="#" class="dropdown-toggle" data-toggle="dropdown">connect<b class="caret"></b></a> <ul class="dropdown-menu"> <li><a href="/contact-us">contact us</a></li> <li><a href="/careers">careers</a></li> <li><a href="/help">help</a></li> <li><a href="/login">user login</a></li> </ul> </li> {% if request.get_full_path != "/" %} <li class="dropdown"> <a href="/contact-us">contact</a> </li> {% else %} <li class="dropdown"> <a href="#contact">contact</a> </li> {% endif %} <!-- navbar search --> <li class="hidden-xs" id="navbar-search"> <a href="#"> <i class="fa fa-search"></i> </a> <div class="hidden" id="navbar-search-box"> <div class="input-group"> <input type="text" class="form-control" placeholder="search"> <span class="input-group-btn"> <button class="btn btn-default" type="button">go!</button> </span> </div> </div> </li> </ul> <!-- mobile search --> <form class="navbar-form navbar-right visible-xs" role="search"> <div class="input-group"> <input type="text" class="form-control" placeholder="search"> <span class="input-group-btn"> <button class="btn btn-red" type="button">search!</button> </span> </div> </form> </div><!--/.nav-collapse --> </div> </div> </header> <!-- / .navigation --> {% block content %} {% endblock %} <!-- footer ================================================== --> <footer> <div class="container"> <div class="row"> <!-- contact --> <div class="col-sm-4"> <h4><i class="fa fa-map-marker text-red"></i> contact us</h4> <p>do not hesitate contact if have questions or feature requests:</p> <p> omaha, ne 68154<br /> 14301 fnb parkway, suite 100<br /> phone: +1 402 957 1336<br /> email: <a href="mailto:sales@multimechrd.com">sales@multimechrd.com</a> </p> </div> <!-- recent tweets --> {% load twitter_tag cache %} {% cache 60 my_tweets %} {% get_tweets "multimechanics" tweets limit 2 %} <div class="col-sm-4"> <h4><i class="fa fa-twitter-square text-red"></i> recent tweets</h4> {% tweet in tweets %} <div class="tweet"> <i class="fa fa-twitter fa-2x"></i> <p> {{ tweet.html|safe }} </p> </div> {% endfor %} </div> {% endcache %} <!-- newsletter --> <div class="col-sm-4"> <h4><i class="fa fa-envelope text-red"></i> newsletter</h4> <p> come in e-mail below subscribe our free newsletter. <br> promise not bother often! </p> <!--<form class="form" role="form" method="post" action="/newsletter{{ request.get_full_path }}">--> <form action="https://www.salesforce.com/servlet/servlet.webtolead?encoding=utf-8" method="post"> <input type=hidden name="oid" value="00di0000000fkhm"> <input type=hidden name="returl" value="http://multimech2.azurewebsites.net/thanks/newsletter"> <input type=hidden name="lead_source" id="lead_source" value="web"> <input type=hidden name="city" id="city" value="{{ip}}"> {% csrf_token %} <div class="row"> <div class="col-sm-8"> <div class="input-group"> <label class="sr-only" for="subscribe-email">email address</label> <!--<input type="email" class="form-control" id="subscribe-email" placeholder="enter email">--> <div class="fieldwrapper">{{ newsletter_form.email }}</div> <span class="input-group-btn"> <button type="submit" class="btn btn-default" name="newsletter_form">ok</button> </span> </div> </div> </div> </form> </div> </div> </div> </footer> <!-- copyright --> <div class="container"> <div class="row"> <div class="col-sm-12"> <div class="copyright"> copyright 2014 - multimechanics, llc | rights reserved </div> </div> </div> <!-- / .row --> </div> <!-- / .container --> <!-- bootstrap core javascript ================================================== --> <!-- placed @ end of document pages load faster --> {% compress js %} <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script src="{{ static_url }}js/bootstrap.min.js"></script> <script src="{{ static_url }}js/scrolltopcontrol.js"></script> <script src="{{ static_url }}js/lightbox-2.6.min.js"></script> <script src="{{ static_url }}js/custom.js"></script> {% endcompress %} {% block otherfooter %}{% endblock %} </body> </html>

here total child:

{% extends "base.html" %} {% block content %} <!-- wrapper --> <div class="wrapper"> <!-- topic header --> <div class="topic"> <div class="container"> <div class="row"> <div class="col-sm-4"> <h3>sign in</h3> </div> <div class="col-sm-8"> <ol class="breadcrumb pull-right hidden-xs"> <li><a href="/">home</a></li> <li class="active">log in</li> </ol> </div> </div> </div> </div> <div class="container"> <div class="row"> <div class="col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-2"> <div class="sign-form"> <div class="sign-inner"> <h3 class="first-child">log in account</h3> <hr> <form role="form" action="" method="post"> {% csrf_token %} <div class="input-group"> <span class="input-group-addon"><i class="fa fa-user"></i></span> {{form.username}} </div> <br> <div class="input-group"> <span class="input-group-addon"><i class="fa fa-lock"></i></span> {{form.password}} </div> <div class="checkbox"> <!--<label> <input type="checkbox"> remember me </label>--> </div> <button type="submit" class="btn btn-red" name="login_form">submit</button> <hr> </form> <p>not registered? <a href="/register">create account.</a></p> <div class="pwd-lost"> <div class="pwd-lost-q show">lost password? <a href="#">click here recover.</a></div> <!--https://github.com/brutasse/django-password-reset--> <div class="pwd-lost-f hidden"> <p class="text-muted">enter email address below , send link reset password.</p> <form class="form-inline" role="form"> <div class="form-group"> <label class="sr-only" for="email-pwd">email address</label> <input type="email" class="form-control" id="email-pwd" placeholder="enter email"> </div> <button type="submit" class="btn btn-blue">send</button> </form> </div> </div> <!-- / .pwd-lost --> </div> </div> </div> </div> <!-- / .row --> </div> <!-- / .container --> </div> <!-- / .wrapper --> {% endblock %}

here how html rendered:

<html lang="en"> <head> <style type="text/css"></style> </head> <body style=""> <!-- base.html --> <!--[if lt ie 8 ]><html class="ie ie7" lang="en"> <![endif]--> <!--[if ie 8 ]><html class="ie ie8" lang="en"> <![endif]--> <!--[if (gte ie 8)|!(ie)]><!--> <!--<![endif]--> <meta charset="utf-8"> <!--<meta http-equiv="x-ua-compatible" content="ie=edge">--> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- navigation --> <header> <div class="navbar navbar-default navbar-fixed-top" role="navigation"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> <span class="sr-only">toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="/"><img src="/static/img/logo.png" alt="..."></a> </div> <div c

here how render page (but utilize "render_to_response" other templates , same result:

url(r'^about-us/', templateview.as_view(template_name="about-us.html"), name='about-us'),

thanks in advance help.

are sure you're editing right "base.html" file? appears may editing file has same name, in different location. also, using javascript or populate <navigation> </navigation> ? rendered result not match base.html. if generating navigation section using javascript, culprit. if redacted readability, search instance of "base.html" or "about-us.html" in project folder. may find editing wrong file. can post finish files "base.html" , "about-us.html" , entire response?

edit: believe issue may in "othermeta" block. can see next lines render correctly:

<meta charset="utf-8"> <!--<meta http-equiv="x-ua-compatible" content="ie=edge">--> <meta name="viewport" content="width=device-width, initial-scale=1">

this point in result gets messy. point in base of operations when phone call {% block othermeta %}. there reason have block content inside? i'm not sure accepting {% endblock %} correctly. if want block othermeta dynamic, must have in own othermeta.html, extends base.html well. then, alter code simply:

{% block othermeta %} {% endblock %}

i think error may you're trying define contents of block in extended template. i'm new @ you, wrong, seek removing othermeta block exclusively , see if helps.

hope helps!

django django-templates

No comments:

Post a Comment