1

I'm trying to print my products from sqlite the problem is that the result in the browser is the code itself and not the value.

views.py:

from django.shortcuts import render
from django.http import HttpResponse
from .models import Product


def index(request):
    products = Product.objects.all()
    return render(request, 'index.html', {'dict': products})

index.html:

<ul>
    {% for prod in dict %}
        <li>{{ prod.name }}</li>
    {% endfor %}
</ul>

The result in the browser is:

{% for prod in dict %}
{{ prod.name }}
{% endfor %}
1
  • How are you checking your results? Are you running the server or directly opening index.html Commented Jan 16, 2021 at 20:01

2 Answers 2

1

In order to fix this you need to check index.html by running the server

python manage.py runserver

and going to the url that leads to index.html

Sign up to request clarification or add additional context in comments.

Comments

0

if the result in the browser is like the one you said, are you opening the HTML file directly? because if Django rendered the template it wouldn't show this. even if the data is wrong or there is nothing, it'll just display nothing

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.