Django template blocks not showing?
I'm having a problem with displaying the contents within the block tags of a child template. I have a base.html and a dash.html which extends the base. When I go to the dash.html page the base.html is extended but the contents set within the block tags of dash.html do not show up. So I get the same thing when I go base.html and dash.html.
Here is my code:
base.html
<!DOCTYPE HTML>
<!--[if lt IE 7 ]> <html class="no-js ie6" lang="en"> <![endif]-->
<!--[if IE 7 ]> <html class="no-js ie7" lang="en"> <![endif]-->
<!--[if IE 8 ]> <html class="no-js ie8" lang="en"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>SCV Discount</title>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
<link rel="stylesheet" href="static/css/main.css">
<script src="http://cdnjs.cloudflare.com/ajax/libs/modernizr/2.0.6/modernizr.min.js"></script>
</head>
<body>
<!-- Main Header -->
<div id="top">
<div id="header">
<a href="/"><div id="logo"></div></a>
{% block head %}{% endblock %}
</div>
</div>
<!-- Middle -->
<div id="mid">
{% block mid %}{% endblock %}
</div>
<!-- Content -->
<div id="analytics-content">
{% block main %}{% endblock %}
</div>
<!-- Scripts -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="static/js/libs/jquery-1.6.2.min.js">\x3C/script>')</script>
<script src="static/js/libs/select.js"></script>
<script src="static/js/main.js"></script>
</body>
</html>
dash.html
{% extends 'base.html' %}
{% block head %}
<p class="dashboard-title">Elephant开发者_开发技巧 Bar</p>
<p class="cp_badge round">Control Panel</p>
{% endblock %}
{% block mid %}
{% include 'modules/meters.html' %}
{% include 'modules/client_ctl.html' %}
{% endblock %}
{% block main %}
{% include 'modules/history.html' %}
{% endblock %}
view.py
from django.shortcuts import render_to_response, get_object_or_404
from django.http import HttpResponse, HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.template import RequestContext
import datetime
def index(request):
return render_to_response('base.html', RequestContext(request))
def dash(request):
return render_to_response('dash.html', RequestContext(request))
Hope that is enough information. Please let me know what other info I can provide. Thanks in advance. I appreciate it.
I just copied & pasted this code into a new project and it is working for me. What does your urls.py look like? Is it possible you are sending your dash url to the index view? Here is the quick urls.py that I wrote to get this up and running:
from django.conf.urls.defaults import *
import views
urlpatterns = patterns('',
(r'^index/', views.index),
(r'^dash/', views.dash),
)
When you view dash.html in your browser (through whatever URL you want to be tied to the dash view), how do you know that it is extending base.html if you do not see any of code that is specific to dash.html?
精彩评论