Skip to content

Commit 6e66808

Browse files
committed
Kategori işlemleri yapıldı.
1-) Eğer mevcut kategori yoksa ise 404 sayfası yönlendirme. 2-) Eğer Kategoride yazı yoksa uyarı.
1 parent ad5b5ae commit 6e66808

File tree

2 files changed

+67
-24
lines changed

2 files changed

+67
-24
lines changed

Blog/views.py

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,78 @@
11
from django.shortcuts import render
2-
from Blog.models import post,category
2+
from Blog.models import post, category
3+
4+
35
# Create your views here.
46
def home(request):
57
"""Ana Sayfa"""
68
db = post.objects.order_by('?')[:6]
7-
return render(request,'profil.html',{
8-
'db':db
9+
return render(request, 'profil.html', {
10+
'db': db
911
})
1012

13+
1114
def about(request):
1215
""" Hakkımda Sayfası """
1316
last_db = post.objects.order_by('?')[:3]
14-
return render(request,'about.html',{
15-
'last_db':last_db
17+
return render(request, 'about.html', {
18+
'last_db': last_db
1619
})
1720

21+
1822
def contact(request):
1923
""" İletişim Sayfası """
2024
last_db = post.objects.order_by('?')[:3]
21-
return render(request,'contact.html',{
25+
return render(request, 'contact.html', {
2226
'last_db': last_db
2327
})
2428

29+
2530
def blog(request):
2631
""" Blog yazıların listelendiği sayfa"""
2732
last_db = post.objects.order_by('?')[:3]
2833
db = post.objects.all()
2934
category_db = category.objects.all()
30-
return render(request,'blog.html',{
35+
return render(request, 'blog.html', {
3136
'last_db': last_db,
32-
'db':db,
33-
'category_db':category_db
37+
'db': db,
38+
'category_db': category_db
3439
})
3540

36-
def makale(request,slug):
41+
42+
def makale(request, slug):
3743
""" makale_details sayfası """
3844
last_db = post.objects.order_by('?')[:3]
3945
category_db = category.objects.all()
4046
db = post.objects.filter(seo_url=slug)
41-
return render(request,'blog_details.html',{
47+
return render(request, 'blog_details.html', {
4248
'last_db': last_db,
43-
'db':db,
44-
'category_db':category_db
49+
'db': db,
50+
'category_db': category_db
4551
})
46-
def category_view(request,category_names):
52+
53+
54+
def category_view(request, category_names):
4755
""" category details sayfası """
4856
last_db = post.objects.order_by('?')[:3]
4957
category_db_list = category.objects.all()
5058
category_db = category.objects.filter(category_name=str(category_names))
5159
post_db = post.objects.filter(category_list__category_name=category_names)
52-
return render(request,'category.html',{
60+
return render(request, 'category.html', {
5361
'last_db': last_db,
54-
'category_db_list':category_db_list,
55-
'category_db':category_db,
56-
'post_db':post_db
62+
'category_db_list': category_db_list,
63+
'category_db': category_db,
64+
'post_db': post_db,
65+
'category_names':category_names
5766
})
5867

68+
5969
def human(request):
6070
""" humans.txt"""
61-
return render(request,'humans.html')
71+
72+
return render(request, 'humans.html')
73+
74+
6275
def robots(request):
6376
"""robots.txt"""
64-
return render(request,'robots.html')
77+
78+
return render(request, 'robots.html')

templates/category.html

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,52 @@
2424
<div class="col-lg-8 col-lg-offset-2 centered">
2525

2626
<h3><i class="{{ i.category_icon }}" aria-hidden="true"> {{ i.category_name }}</i></h3>
27-
<p>{{ i.category_description }}</p>
27+
{% if not post_db %}
28+
<h3>Hiçbir yazı bulunamadı malesef :(</h3>
29+
<hr>
30+
<p>Daha önceden silinmiş veya hiç eklenmemiş olabilir.</p>
31+
{% else %}
32+
<p>{{ i.category_description }}</p>
33+
{% endif %}
2834

2935
</div><!-- /col-lg-8 -->
3036
</div><!-- /row -->
3137
</div> <!-- /container -->
3238
</div><!-- /ww -->
33-
{% endfor %}
3439

40+
41+
{% empty %}
42+
<!-- +++++ Welcome Section +++++ -->
43+
<div id="ww">
44+
<div class="container">
45+
<div class="row">
46+
<div class="col-lg-8 col-lg-offset-2 centered">
47+
<h3>404 Page not found </h3>
48+
49+
<p>Böyle bir kategori bulunamadı!</p>
50+
<hr>
51+
<p>Daha sonradan silinmiş veya hiç eklenmemiş olabilir.</p>
52+
53+
</div><!-- /col-lg-8 -->
54+
</div><!-- /row -->
55+
</div> <!-- /container -->
56+
</div><!-- /ww -->
57+
58+
59+
<!-- +++++ Information Section +++++ -->
60+
61+
{% endfor %}
3562
<!-- +++++ Projects Section +++++ -->
36-
<div class="container pt">
37-
<div class="row mt centered">
63+
{% if post_db %}
64+
<div class="container pt">
65+
<div class="row mt centered">
3866
{% for i in post_db %}
3967
<div class="col-lg-4">
4068
<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>
4169
<p>{{ i.title }}</p>
4270
</div>
4371
{% endfor %}
72+
{% endif %}
4473
</div><!-- /row -->
4574
</div><!-- /container -->
4675
{% endblock %}

0 commit comments

Comments
 (0)