B
B
bayko042020-08-02 04:27:20
Django
bayko04, 2020-08-02 04:27:20

How to display a row from the database so that when it is output, it replaces itself?

TO BE HONEST, CAN YOU EXPLAIN IN GENERAL HOW TO MAKE A SLIDE AT THE SAME TIME AND CLICK ON IT TO OPEN THE INFORMATION PAGE I DID THIS

models.py

from django.db import models
from PIL import Image


class News(models.Model):

    NameNews = models.CharField(max_length=20)
    OfferNews = models.TextField(max_length=100)
    TitleNews = models.CharField(max_length=35)
    DescriptionNews = models.TextField()

    def __str__(self):
        return self.NameNews

    class Meta:
        verbose_name = 'Новость'
        verbose_name_plural = 'Новости'


views.py

from django.shortcuts import render
from .models import News

def obito(request):
    news = News.objects.all()
    context = {
        'pr': news
    }
    return render(request, 'loli/News.html', context)


def madara(request):
    news = News.objects.all()
    context = {
        'pr': news
    }
    return render(request, 'loli/news-offer.html', context)


News.html
This is the slide itself, it redirects to a separate page.

<section class="skill">
        <div class="container">
            <div class="row">
                {% for post in pr %}
                <div class="col-md-4">
                    <a href="{% url 'madara' %}" class="pointer">
                        <div class="card">
                            <div class="card-img">
                                <img src="image/Card2.svg" alt="car" class="card-img2">
                            </div>
                            <h3 class="card-title">
                                {{ post.NameNews}}
                            </h3>
                            <p class="card-offer">
                                {{ post.OfferNews}}
                            </p>
                        </div>
                    </a>
                </div>
                {% endfor %}


madara
This is the page where all tables appear at the same time

<section class="news-list">
        <div class="container">
            <div class="row">
                <div class="col-md-12">
                        {% for post in pr %}
                        <h2 class="news-list_title">
                            {{ post.TitleNews}}
                        </h2>
                        <p class="news-list_offer">
                            {{ post.DescriptionNews}}
                        </p>
                        {% endfor %}
                </div>
            </div>
        </div>
    </section>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2020-08-04
@dimonchik2013

if it works, then go

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question