Content not visible on webpage

Question:

I am creating a database website with python and django. My problem is that the content I try to get data from my class’ fields doesn’t appear on the id-page on django. I am able to make a successful search, and I get links for my searches. The name-field is visible in searches and on the page, but nothing else appears. When I click on the link, I go to luokka_id/number. I must be missing something but can’t figure out what the problem is.

models.py

class luokka(models.Model):
    nimi = models.CharField('Pääkäyttöluokka', max_length=100)
    vara = models.CharField('Varakäyttöluokka', max_length=100)
    varaaja = models.CharField('Varakäyttöluokka', max_length=100)
    def __str__(self):
        return self.nimi

and on the näytä_luokka.html (show class):

{% extends 'tietokanta/base.html' %}

{% block content %}

<center>
    
{{luokkalistaus}}
{{luokka}}


{{ luokka.nimi }}
{{ luokka.vara }}
{{ luokka.varaaja }}


    
</center>

{% endblock %}

and views.py:

def näytä_luokka(request, luokka_id):
    luokkalistaus = luokka.objects.get(pk=luokka_id)
    return render(request, 'tietokanta/näytä_luokat.html', 
        {'luokkalistaus': luokkalistaus})

I don’t get any errors to help me out here. It’s just an empty page, but it should show some extra data.

Asked By: Charoi

||

Answers:

You have named the key of context as luokkalistaus not luokka, so the template should be:

{% extends 'tietokanta/base.html' %}

{% block content %}

<center>

{{ luokkalistaus.nimi }}
{{ luokkalistaus.vara }}
{{ luokkalistaus.varaaja }}
   
</center>

{% endblock %}
Answered By: Sunderam Dubey
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.