1. Trying out Django first time and my product view is now fetching data through templates.Occasionally, pycharm warns about invalid indent, but I resolved it with unnecessary space.

  2. Here is the 'base.html' file:

<!doctype html>
<html>
<head>
    <title>Programmierung ist schön.</title>
</head>

<body>
    <!-- <h1>This is navbar</h1> -->
    {% include 'navbar.html' %}

    {% block content %}
        replace me
    {% endblock %}

    {% block another_content %}
        replace me
    {% endblock another_content %}
</body>
</html>
  1. Here is the product\detail.html file:
{% extends 'base.html' %}

{% block content %}

    <h1>{{ item }}</h1>
    <p>{ % if description  } {{ description }} { % else %  } Description Coming Soon { % endif % }</p>

{% endblock %}
  1. Error from Safari Browser:
AttributeError at /product
'tuple' object has no attribute 'get'
Request Method: GET
Request URL:    http://127.0.0.1:8000/product
Django Version: 2.0.7
Exception Type: AttributeError
Exception Value:    
'tuple' object has no attribute 'get'
Exception Location: /Users/kuldeep/Dev/trydjango/lib/python3.7/site-packages/django/middleware/clickjacking.py in process_response, line 26
Python Executable:  /Users/kuldeep/Dev/trydjango/bin/python
Python Version: 3.7.0
Python Path:    
['/Users/kuldeep/Dev/trydjango/src',
 '/Users/kuldeep/Dev/trydjango/lib/python37.zip',
 '/Users/kuldeep/Dev/trydjango/lib/python3.7',
 '/Users/kuldeep/Dev/trydjango/lib/python3.7/lib-dynload',
 '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7',
 '/Users/kuldeep/Dev/trydjango/lib/python3.7/site-packages']
Server time:    Mon, 29 Apr 2019 09:53:16 +0000

Here is the view.html file.

from django.shortcuts import render

from .models import Product
# Create your views here.

def product_detail_view(request):
    obj = Product.objects.get(id=1)
    context = {
        'title': obj.title,
        'description': obj.description,
        'summary': obj.summary,
    }
    return render(request, "product/detail.html", context),

1 Answers

0
Daniel Roseman On Best Solutions

You have a simple typo: an extra comma at the end of your last line.

return render(request, "product/detail.html", context),

should be

return render(request, "product/detail.html", context)