From f47f8cb8521ce78afa2525c62a84d3d1a643b54c Mon Sep 17 00:00:00 2001 From: Sven Arnold Date: Mon, 8 Feb 2016 17:19:40 +0100 Subject: [PATCH] first use of templates --- project/books/templates/books/index.html | 9 +++++++++ project/books/views.py | 10 ++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 project/books/templates/books/index.html diff --git a/project/books/templates/books/index.html b/project/books/templates/books/index.html new file mode 100644 index 0000000..2b440e1 --- /dev/null +++ b/project/books/templates/books/index.html @@ -0,0 +1,9 @@ +{% if book_list %} + +{% else %} + Keine Bücher im Regal! +{% endif %} diff --git a/project/books/views.py b/project/books/views.py index aa62cca..1f7be40 100644 --- a/project/books/views.py +++ b/project/books/views.py @@ -1,11 +1,17 @@ from django.shortcuts import render from django.http import HttpResponse +from django.template import RequestContext, loader from books.models import Book, Lease def index(request): - books = ", ".join([str(b) for b in Book.objects.all()]) - return HttpResponse(books) + book_list = Book.objects.all() + template = loader.get_template('books/index.html') + context = RequestContext(request, { + 'book_list': book_list, + }) + return HttpResponse(template.render(context)) + def detail(request, book_id): response = "Book ID: %s" -- 2.11.0