Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Content not visible on webpage

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):

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{% 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.

>Solution :

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 %}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading