Created a separate handler for the main page
It displays the last five blog entries
This commit is contained in:
parent
4cb97ed97a
commit
e04a7c6fda
@ -2,10 +2,14 @@ import datetime
|
|||||||
from django.shortcuts import render, get_object_or_404
|
from django.shortcuts import render, get_object_or_404
|
||||||
from blog.models import Post
|
from blog.models import Post
|
||||||
|
|
||||||
def index(request):
|
def mainpage(request):
|
||||||
last_posts = Post.objects.order_by('-created_at')[:5]
|
last_posts = Post.objects.order_by('-created_at')[:5]
|
||||||
return render(request, 'blog/listing.html', {'posts': last_posts})
|
return render(request, 'blog/listing.html', {'posts': last_posts})
|
||||||
|
|
||||||
|
def index(request):
|
||||||
|
last_posts = Post.objects.order_by('-created_at')
|
||||||
|
return render(request, 'blog/listing.html', {'posts': last_posts})
|
||||||
|
|
||||||
def read(request, year, month, day, slug):
|
def read(request, year, month, day, slug):
|
||||||
post = get_object_or_404(Post, created_at__year=int(year), created_at__month=int(month), created_at__day=int(day), slug=slug);
|
post = get_object_or_404(Post, created_at__year=int(year), created_at__month=int(month), created_at__day=int(day), slug=slug);
|
||||||
return render(request, 'blog/view.html', {'post': post})
|
return render(request, 'blog/view.html', {'post': post})
|
||||||
|
@ -5,7 +5,7 @@ admin.autodiscover()
|
|||||||
|
|
||||||
urlpatterns = patterns('',
|
urlpatterns = patterns('',
|
||||||
# Examples:
|
# Examples:
|
||||||
url(r'^$', 'blog.views.index', name='home'),
|
url(r'^$', 'blog.views.mainpage', name='home'),
|
||||||
# url(r'^$', 'gergelypolonkai_django.views.home', name='home'),
|
# url(r'^$', 'gergelypolonkai_django.views.home', name='home'),
|
||||||
url(r'^blog/', include('blog.urls', namespace='blog')),
|
url(r'^blog/', include('blog.urls', namespace='blog')),
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user