Skip to content

Commit fa59c0e

Browse files
committed
Kategori sayfalama eklendi.
1 parent 3256fcd commit fa59c0e

File tree

5 files changed

+98
-5
lines changed

5 files changed

+98
-5
lines changed

Blog/views.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from django.shortcuts import render,get_list_or_404
22
from Blog.models import post, category
3-
from django.core.paginator import Paginator
3+
from django.core.paginator import Paginator,EmptyPage
4+
from django.http import Http404
45

56
# Create your views here.
67
def home(request):
@@ -48,8 +49,11 @@ def page(request,id):
4849
post_db = post.objects.all()
4950
category_db = category.objects.all()
5051
pages = Paginator(post_db,5)
51-
db = pages.page(id)
52-
return render(request, 'blog.html', {
52+
try:
53+
db = pages.page(id)
54+
except EmptyPage:
55+
raise Http404()
56+
return render(request, 'page.html', {
5357
'last_db': last_db,
5458
'db': db,
5559
'pages': pages,
@@ -75,11 +79,33 @@ def category_view(request, category_names):
7579
category_db_list = category.objects.all()
7680
category_db = category.objects.filter(category_name=str(category_names))
7781
post_db = post.objects.filter(category_list__category_name=category_names)
82+
pages = Paginator(post_db,5)
7883
return render(request, 'category.html', {
7984
'last_db': last_db,
8085
'category_db_list': category_db_list,
8186
'category_db': category_db,
8287
'post_db': get_list_or_404(post_db),
88+
'pages':pages,
89+
'category_names':category_names
90+
})
91+
92+
def category_page(request, category_names,id):
93+
""" category details sayfası """
94+
last_db = post.objects.order_by('?')[:3]
95+
category_db_list = category.objects.all()
96+
category_db = category.objects.filter(category_name=str(category_names))
97+
post_db = post.objects.filter(category_list__category_name=category_names)
98+
pages = Paginator(post_db,5)
99+
try:
100+
db = pages.page(id)
101+
except EmptyPage:
102+
raise Http404()
103+
return render(request, 'category_page.html', {
104+
'last_db': last_db,
105+
'category_db_list': category_db_list,
106+
'category_db': category_db,
107+
'post_db': db,
108+
'pages':pages,
83109
'category_names':category_names
84110
})
85111

BlogProject/urls.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
from django.contrib import admin
1818
from django.conf import settings
1919
from django.views.static import serve
20-
from Blog.views import home,about,contact,blog,blog_details,category_view,human,robots,page
20+
from Blog.views import (home,about,contact,blog,
21+
blog_details,category_view,human,robots,page,category_page)
2122

2223
from Blog.sitemaps import StaticViewSitemap
2324
from django.contrib.sitemaps.views import sitemap
@@ -34,6 +35,7 @@
3435
url(r'^kategori/(?P<category_names>\w+)/$', category_view, name='category_view'),
3536
url(r'^makale/(?P<slug>[\w-]+)/$', blog_details, name='makale'),
3637
url(r'^sayfa/(?P<id>\d+)', page, name='page'),
38+
url(r'^kategori/(?P<category_names>\w+)/(?P<id>\d+)', category_page, name='category_page'),
3739
url(r'^humans.txt$', human, name='human'),
3840
url(r'^robots.txt$', robots, name='human'),
3941
url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps},name='django.contrib.sitemaps.views.sitemap')

templates/blog.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ <h4 class="">Kategoriler</h4>
5858

5959
{% for i in db %}
6060
<div class="row">
61-
<div class="col-sm-4"><a href="#" class=""><img src="http://127.0.0.1:8000/media/{{ i.image }}" class="img-responsive"></a>
61+
<div class="col-sm-4"><a href="/makale/{{ i.seo_url }}" class=""><img src="http://127.0.0.1:8000/media/{{ i.image }}" class="img-responsive"></a>
6262
</div>
6363
<div class="col-sm-8">
6464
<h3 class="title"><a href="/makale/{{ i.seo_url }}">{{ i.title }}</a></h3>

templates/category.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ <h3><i class="{{ i.category_icon }}" aria-hidden="true"> {{ i.category_name }}</
4444
{% endfor %}
4545
{% endif %}
4646
</div><!-- /row -->
47+
<ul class="pagination pagination-lg pull-right">
48+
{% for i in pages.page_range %}
49+
<li><a href="/kategori/{{ category_names }}/{{ i }}">{{ i }}</a></li>
50+
{% endfor %}
51+
</ul>
4752
</div><!-- /container -->
53+
4854
{% endblock %}
4955
{% block last_content %}
5056
{% for i in last_db %}

templates/category_page.html

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{% extends 'base.html' %}
2+
{% load static %}
3+
{% block category %}
4+
<li class="dropdown">
5+
<a href="#" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Kategoriler <span class="caret"></span></a>
6+
<ul class="dropdown-menu">
7+
{% for i in category_db_list %}
8+
<li><a href="/kategori/{{ i.category_name }}">{{ i.category_name }}</a></li>
9+
{% endfor %}
10+
</ul>
11+
</li>
12+
{% endblock %}
13+
<!-- SEO -->
14+
{% block description %}Ali Yaman hakkında bilgiler içermektedir.{% endblock %}
15+
16+
{% block keywords %}kişisel blog, blog, programlama, kişisel gelişim, bloglama, developer blog{% endblock %}
17+
18+
{% block content %}
19+
<!-- +++++ Welcome Section +++++ -->
20+
{% for i in category_db %}
21+
<div id="ww">
22+
<div class="container">
23+
<div class="row">
24+
<div class="col-lg-8 col-lg-offset-2 centered">
25+
26+
<h3><i class="{{ i.category_icon }}" aria-hidden="true"> {{ i.category_name }}</i></h3>
27+
<p>{{ i.category_description }}</p>
28+
29+
</div><!-- /col-lg-8 -->
30+
</div><!-- /row -->
31+
</div> <!-- /container -->
32+
</div><!-- /ww -->
33+
34+
{% endfor %}
35+
<!-- +++++ Projects Section +++++ -->
36+
{% if post_db %}
37+
<div class="container pt">
38+
<div class="row mt centered">
39+
{% for i in post_db %}
40+
<div class="col-lg-4">
41+
<a class="zoom green" href="/makale/{{ i.seo_url }}"><img width="500" height="200" src="http://127.0.0.1:8000/media/{{ i.image }}" alt="" /></a>
42+
<p>{{ i.title }}</p>
43+
</div>
44+
{% endfor %}
45+
{% endif %}
46+
</div><!-- /row -->
47+
<ul class="pagination pagination-lg pull-right">
48+
{% for i in pages.page_range %}
49+
<li><a href="/kategori/{{ category_names }}/{{ i }}">{{ i }}</a></li>
50+
{% endfor %}
51+
</ul>
52+
</div><!-- /container -->
53+
54+
{% endblock %}
55+
{% block last_content %}
56+
{% for i in last_db %}
57+
<a href="/makale/{{ i.seo_url }}"><i class="fa fa-share" aria-hidden="true"></i> {{ i.title }}</a><br/>
58+
{% endfor %}
59+
{% endblock %}

0 commit comments

Comments
 (0)