Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialLogesh Jayaraman
445 PointsWeb Design
In Django can we have the templates not related to any of the models. For example
(a) Home Page can be the static template without the requirement of the models? Is it possible to have it. If yes what is the best practice do i need to create an App for static and use it or just use the project template folder itself
1 Answer
Chris Freeman
Treehouse Moderator 68,454 PointsYou can have views and templates that do not reference a model. See this StackOverflow Post.
- in Django 1.5+ Use the class based generic views (docs)
from django.views.generic import TemplateView
urlpatterns = patterns('',
(r'^foo/$', TemplateView.as_view(template_name='foo.html')),
)
- Django 1.4 (docs)
urlpatterns = patterns('django.views.generic.simple',
(r'^foo/$', 'direct_to_template', {'template': 'foo_index.html'}),
(r'^foo/(?P<id>\d+)/$', 'direct_to_template', {'template': 'foo_detail.html'}),
)
Also, Flatpages is a way to serve up static pages that aren't found via the URL --> view --> template path.
And it lets you take advantage of the templating system when there is a base templates/flatpages/default.html
that extends your base layout.html
file.
Flatpage URLs are checked after exhausting all other defined URLs.
.