Created
October 21, 2018 06:22
-
-
Save dura0ok/cb37d3a036783f3f7daef541fd237949 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends '../base.html' %} | |
{% load staticfiles %} | |
{% block content %} | |
<div class="news"> | |
{% for item in articles %} | |
<h1>{{ item }} </h1> | |
<img height="500" width="800" src="{{ item.image.url }}" alt="img" > <br> | |
<p>{{ item.text }}</p> | |
<a href="/article/{{ item.id }}"><button>Продолжить?</button></a> | |
{% endfor %} | |
<div class="pagination"> | |
<span class="step-links"> | |
{% if articles.has_previous %} | |
<a href="?page=1">« first</a> | |
<a href="?page={{ articles.previous_page_number }}">previous</a> | |
{% endif %} | |
<span class="current"> | |
Page {{ articles.number }} of {{ articles.paginator.num_pages }}. | |
</span> | |
{% if articles.has_next %} | |
<a href="?page={{ articles.next_page_number }}">next</a> | |
<a href="?page={{ articles.paginator.num_pages }}">last »</a> | |
{% endif %} | |
</span> | |
</div> | |
</div> | |
{% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.shortcuts import render | |
from django.views.generic import ListView, DetailView | |
# Create your views here. | |
from .models import New | |
def home(request): | |
item = New.objects.filter(main=1).last() | |
context = { | |
'last': item | |
} | |
return render(request, 'home.html', context=context) | |
class NewsList(ListView): | |
model = New | |
queryset = New.objects.filter(main=0).order_by('id') | |
template_name = 'pages/news.html' | |
context_object_name = 'articles' | |
paginate_by = 1 | |
def get_context_data(self, **kwargs): | |
item = New.objects.filter(main=1).last() | |
context = super().get_context_data(**kwargs) | |
context['last'] = item | |
return context |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment