Answer the question
In order to leave comments, you need to log in
Django. How to open detailed information for news/products?
Hi everyone, help needed! I am developing a site, it has a model that posts news on the main page through the admin panel. Here is her code:
models.py:
Class Task(models.Model):
title = models.CharField('Название', max_length=50, help_text='Введите название')
text = models.TextField('Описание')
text1 = models.TextField('Подробное Описание', null=True,)
img = models.ImageField("Изображение", upload_to="media/", null=True, )
time = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.title
def index(request):
news = Task.objects.order_by('-id')
return render(request, 'main/index.html', {'tasks': news})
{ % block content %}
{% for el in tasks %}
<div class="news imgb">
<nav>
<a href="{% url 'news' %}">
<h3>
{{ el.title }}
</h3>
И так далее, там вывод фотки, описания и времени.
urlpatterns = [
path('', views.index, name='home'),
path('about', views.about, name='about'),
path('learners', views.learn, name='learn'),
path('galery', views.galery, name='galery'),
url('news/$', views.Task_list.as_view(), name='news'),
]
class Task_list(generic.ListView):
news_one = Task
Answer the question
In order to leave comments, you need to log in
according to https://docs.djangoproject.com/en/3.1/ref/class-ba...
class Task_list(generic.ListView):
model = Task
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question