Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

this is my views.py

def sms(request):
    obj = Sms.objects.all()

    return render(request, 'advisory.html', {'sms': obj})

and this is on my html.

    {% for i in sms %}
    <tr>
         <td>{{ i.description }}</td>
         <td>{{ i.timestamp }}</td>
    </tr>
    {% endfor %}

this is the model

class Sms(models.Model):
    description = models.CharField(max_length=100, blank=True)
    timestamp = models.DateTimeField(auto_now_add=True)

And i don't really know why its not returning any data from my model. please help! thanks

question from:https://stackoverflow.com/questions/65945317/table-not-displaying-a-data-from-model

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
199 views
Welcome To Ask or Share your Answers For Others

1 Answer

add to you Sms model function like this

def __str__(self):
   return self.description

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...