diff --git a/django/didgeridoo/webshop/templates/webshop/article_details.html b/django/didgeridoo/webshop/templates/webshop/article_details.html index aa66890..e580fdc 100644 --- a/django/didgeridoo/webshop/templates/webshop/article_details.html +++ b/django/didgeridoo/webshop/templates/webshop/article_details.html @@ -1,15 +1,9 @@ - - - - - -
-

{{ article.name }}

-

Description

-

{{ article.description }}

-

Stock: {{ article.stock }}

-

Status: {{ article.status}}

-

Price: {{ article.price_in_chf }}

-
- - +{% extends "webshop/base.html" %} +{% block section_title %}{{ article.name }}{% endblock %} +{% block content %} +

Description

+

{{ article.description }}

+

Stock: {{ article.stock }}

+

Status: {{ article.status}}

+

Price: {{ article.price_in_chf }}

+{% endblock %} diff --git a/django/didgeridoo/webshop/templates/webshop/base.html b/django/didgeridoo/webshop/templates/webshop/base.html new file mode 100644 index 0000000..fa6b702 --- /dev/null +++ b/django/didgeridoo/webshop/templates/webshop/base.html @@ -0,0 +1,17 @@ + + + + + +
+

{% block section_title %}Music Instrument Shop{% endblock %}

+ {% block content %}{% endblock %} +
+ + + diff --git a/django/didgeridoo/webshop/templates/webshop/category.html b/django/didgeridoo/webshop/templates/webshop/category.html index 7e42cfa..373f03f 100644 --- a/django/didgeridoo/webshop/templates/webshop/category.html +++ b/django/didgeridoo/webshop/templates/webshop/category.html @@ -1,21 +1,13 @@ - - - - - - - -
-

{{ category.name }}

-{% if article_list %} - -{% else %} -

There are no articles in this category.

-{% endif %} -
- - +{% extends "webshop/base.html" %} +{% block section_title %}Category Overview{% endblock %} +{% block content %} + {% if article_list %} + + {% else %} +

There are no articles in this category.

+ {% endif %} +{% endblock %} diff --git a/django/didgeridoo/webshop/templates/webshop/index.html b/django/didgeridoo/webshop/templates/webshop/index.html index 721caae..651ea42 100644 --- a/django/didgeridoo/webshop/templates/webshop/index.html +++ b/django/didgeridoo/webshop/templates/webshop/index.html @@ -1,10 +1,5 @@ - - - - - -
-

Music Shop

+{% extends "webshop/base.html" %} +{% block content %} {% if category_list %} {% else %}

No categories are available.

- {% endif %} -
- - + {% endif %} +{% endblock %} diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py index 0db7d06..046ae5f 100644 --- a/django/didgeridoo/webshop/views.py +++ b/django/didgeridoo/webshop/views.py @@ -1,7 +1,4 @@ from django.shortcuts import get_object_or_404, render -from django.http import HttpResponse -from django.template import loader - from .models import Article, Category, ArticleStatus # Create your views here. @@ -15,11 +12,9 @@ def index(request): category_list.update( {i: Category.objects.filter(parent_category=i.id)}) - template = loader.get_template('webshop/index.html') - context = { - 'category_list': category_list, - } - return HttpResponse(template.render(context, request)) + return render(request, + 'webshop/index.html', + {'category_list': category_list}) def articles_in_category(request, category_id): @@ -29,16 +24,12 @@ def articles_in_category(request, category_id): article_list = Article.objects.filter( category=selected_category.id).exclude(status=hidden.id) - template = loader.get_template('webshop/category.html') - context = { - 'article_list': article_list, - 'category': selected_category, - } - return HttpResponse(template.render(context, request)) + return render(request, 'webshop/category.html', + {'article_list': article_list, + 'category': selected_category}) def article_details(request, article_id): article = get_object_or_404(Article, pk=article_id) - return render(request, - 'webshop/article_details.html', + return render(request, 'webshop/article_details.html', {'article': article})