Skip to content

Instantly share code, notes, and snippets.

@findmyway
Last active February 27, 2018 07:24
Show Gist options
  • Save findmyway/f3f1b4c95f8f9a42cb2fbabf266836e3 to your computer and use it in GitHub Desktop.
Save findmyway/f3f1b4c95f8f9a42cb2fbabf266836e3 to your computer and use it in GitHub Desktop.
Another block
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from articles.models import Article
# Create your views here.
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
def essays_preview(request):
article_list = Article.objects.all().order_by("-time")
paginator = Paginator(article_list, 5)
page = request.GET.get('page')
try:
onepage_articles = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
onepage_articles = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
onepage_articles = paginator.page(paginator.num_pages)
for article in onepage_articles:
article.body = markdown(article.body,
extensions=['codehilite'],
extension_configs={'codehilite': [('linenums', True),
('noclasses',
True),
('pygments_style', 'native')]})
context = {'all_essays': article_list,
'onepage_essays': onepage_articles}
return render(request, 'essays_preview.html', context)
"""test"""
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from articles.models import Article
# Create your views here.
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
def essays_preview(request):
article_list = Article.objects.all().order_by("-time")
paginator = Paginator(article_list, 5)
page = request.GET.get('page')
try:
onepage_articles = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
onepage_articles = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
onepage_articles = paginator.page(paginator.num_pages)
for article in onepage_articles:
article.body = markdown(article.body,
extensions=['codehilite'],
extension_configs={'codehilite': [('linenums', True),
('noclasses',
True),
('pygments_style', 'native')]})
context = {'all_essays': article_list,
'onepage_essays': onepage_articles}
return render(request, 'essays_preview.html', context)
"""test"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment