Возникают проблемы с отображением данных в моем веб-приложении
Я пытаюсь получить информацию "О нас" из моей базы данных в мое веб-приложение, но она не отображается, что может быть не так...
вот код из базы данных
class About(models.Model):
about_us = models.TextField()
achieve = models.TextField(blank=True)
image_abt = models.ImageField(upload_to="admin_pics", null=True)
class Meta:
verbose_name_plural = "About Us"
def __str__(self):
return self.about_us
и вот Html код `
{% extends 'jtalks/base.html' %}
{% load static %}
{%block content%}
<section id="about-home">
<h2>About Us</h2>
</section>
<section id="about-container">
{% for about in abouts %}
<div class="about-img">
<img src="{{ about.image_abt.url }}" alt="">
</div>
<div class="about-text">
<h2>Welcome to TechEduca, Enhance your skills with best Online Courses</h2>
<p>{ about.about_us}</p>
<div class="about-fe">
<img src="images/fe1.png" alt="">
<div class="fe-text">
<h5>400+ Courses</h5>
<p>You can start and finish one of these popular courses in under our site</p>
</div>
</div>
<div class="about-fe">
<img src="images/fe2.png" alt="">
<div class="fe-text">
<h5>Lifetime Access</h5>
<p>You can start and finish one of these popular courses in under our site</p>
</div>
</div>
</div>
{% endfor %}
</section>
{% endblock %}
Ничто не отображается во фронтенде сайта.
Спасибо, что поделились своим мнением. Вы забыли передать данные в ваш шаблон. Для этого вам нужно создать queryset и передать его в словарь, как показано ниже. Добавьте контекстную переменную в ваш метод render, чтобы вы могли получить доступ к данным в шаблоне.
def about(request):
about = About.objects.all()
context = {
'abouts': about,
}
return render(request, 'jtalks/about.html', context)
также, в вашем html-коде я вижу { about.about_us}
, но вы должны использовать двойные фигурные скобки: {{ about.about_us }}