From: Sven Arnold Date: Mon, 8 Feb 2016 16:19:40 +0000 (+0100) Subject: first use of templates X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=f47f8cb8521ce78afa2525c62a84d3d1a643b54c;p=urtebook.git first use of templates --- 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"