Reputation: 75
I'm following this tutorial (http://lightbird.net/dbe/cal1.html) to build a calendar app, but I can't get the templates to work correctly.
I made a directory named cal
in project/templates
and copied base.html
there. Then I extended the template cal/main.html
with the following:
{% extends "cal/base.html" %}
<!-- ... -->
<a href="{% url cal.views.main year|add:'-3' %}"><< Prev</a>
<a href="{% url cal.views.main year|add:'3' %}">Next >></a>
{% for year, months in years %}
<div class="clear"></div>
<h4>{{ year }}</h4>
{% for month in months %}
<div class=
{% if month.current %}"current"{% endif %}
{% if not month.current %}"month"{% endif %} >
{% if month.entry %}<b>{% endif %}
<a href="{% url cal.views.month year month.n %}">{{ month.name }}</a>
{% if month.entry %}</b>{% endif %}
</div>
{% if month.n == 6 %}<br />{% endif %}
{% endfor %}
{% endfor %}
In my project/urls.py
I have the following configuration:
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^cal/', include('cal.urls')),
url(r'^admin/', include(admin.site.urls)),
)
In cal/urls.py
I have the following configuration:
from django.conf.urls import patterns, include, url
from cal.views import main
urlpatterns = patterns('cal.views',
(r'^(\d+)/$', main),
(r'', main),
)
I'm not sure where I went wrong. All that is showing up right now when I run the app is a blank screen with a "Home" button on the top left corner that takes me to the admin page. If anyone could point me in the right direction, it would be greatly appreciated!
Upvotes: 0
Views: 168
Reputation: 2476
In base.html you must have something like that:
{% block content %}{% endblock %}
And in main.html:
{% extends "cal/base.html" %}
{% block content %}
<a href="{% url cal.views.main year|add:'-3' %}"><< Prev</a>
<a href="{% url cal.views.main year|add:'3' %}">Next >></a>
{% for year, months in years %}
<div class="clear"></div>
<h4>{{ year }}</h4>
{% for month in months %}
<div class=
{% if month.current %}"current"{% endif %}
{% if not month.current %}"month"{% endif %} >
{% if month.entry %}<b>{% endif %}
<a href="{% url cal.views.month year month.n %}">{{ month.name }}</a>
{% if month.entry %}</b>{% endif %}
</div>
{% if month.n == 6 %}<br />{% endif %}
{% endfor %}
{% endfor %}
{% endblock %}
Upvotes: 2