R
R
Ruslan Bergutov2015-05-08 07:38:56
Django
Ruslan Bergutov, 2015-05-08 07:38:56

How to make a similar view in django?

Me again)
slider.model

class Slide(models.Model):
    image = models.ImageField(u'Изображение')
    header = models.CharField(u'Заголовок', max_length=120, blank=False)
    caption = models.CharField(u'Описание', max_length=250, blank=False)

slider.views
def slider(request):
    slides = Slide.objects.all()
    return render(request, 'main.html', {'slides': slides})

and the same app Promo
promo.models
class Promo(models.Model):
    image = models.ImageField(u'Изображение')
    header = models.CharField(u'Заголовок', max_length=120, blank=False)
    caption = models.CharField(u'Описание', max_length=250, blank=False)

promo.views
def promotion(request):
    promos = Promo.objects.all()
    return render(request, 'base.html', {'promos': promos})

in general, these two applications perform the function of a slider and a share block on the site
urls
url(r'^$', 'slides.views.slider'),
url(r'promo/', 'promos.views.promotion'),

well, I also have separate html separate promo.html and slider.html responsible for the output of slides and promotions, two views above lead to these two html.
There is a similar scheme from html:
base.html
<head>
{% include 'head.html' %}
</head>
<body>
<div class="container">
        {% include 'navbar.html' %}
        <div class="content">
                {% block content %}
                {% endblock %}
        </div>
        <div class="footer">
                {% include "promo.html" %}
        </div>
</div>
</body>

main.html
{% extends 'base.html' %}
{% block content %}
        {% include 'slider.html' %}
{% endblock %}

The bottom line is that when url(r'^$') is called, the slider works, and when url(r'^promo) is called, only the promo, how to make the promo work on all pages without a separate call to the promo view

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Pinkevich, 2015-05-08
@Scirocco

https://toster.ru/answer?answer_id=572613#answers_...
only instead of {'context': data} it will be {'promos': promos}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question