Skip to content

Instantly share code, notes, and snippets.

@dura0ok
Created October 21, 2018 06:22
Show Gist options
  • Save dura0ok/cb37d3a036783f3f7daef541fd237949 to your computer and use it in GitHub Desktop.
Save dura0ok/cb37d3a036783f3f7daef541fd237949 to your computer and use it in GitHub Desktop.
{% 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">&laquo; 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 &raquo;</a>
{% endif %}
</span>
</div>
</div>
{% endblock %}
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