BergeohneSchnee
BergeohneSchnee

Reputation: 13

Content of database not showing up in Django

I have some problems to get the content out of the django database. I'm a bloody beginner at django so I did some tutorials. They've worked fine. Now I want to reproduce them in my own project with own variables so I can see if I've understood all the stuff.

So to come to my problem I initalized my modules in models.py

from django.db import models

class Aboutme(models.Model):
    author = models.CharField(max_length=30)
    ...

This works because I could add content to the database. So there is no mistake.

Now in the views.py

from django.shortcuts import render
from portfolio.models import Aboutme

def portfolio_index(request):
    
    aboutme = Aboutme.objects.all()
    context = {'aboutme': aboutme}

    return render(request, 'portfolio_index.html', context)

So finally in my HTML file, called portfolio_index.html, I call the content via

 <h1>{{ aboutme.author }}</h1>

I guess it's right. But the content of author doesn't showup, so what did I miss? I can call static files via django, so couldn't be something wrong with django...

Can anyone help.

Thanks in advance.

Upvotes: 1

Views: 647

Answers (1)

aurajimenez
aurajimenez

Reputation: 71

I think that you need to use a for loop to show "aboutme" because with "aboutme = Aboutme.objects.all()" you query a list of elements.

{% for aboutme_item in aboutme %}
    <h1>{{ aboutme_item.author }}</h1>
{% endfor %}

Upvotes: 1

Related Questions