Skip to content

Commit e400d44

Browse files
committed
{{ web_site_name }} global olarak belirlendi.
Media işlemlerinde pratiklik için.
1 parent fa59c0e commit e400d44

File tree

16 files changed

+59
-248
lines changed

16 files changed

+59
-248
lines changed

Blog/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class category(models.Model):
66
category_keywords = models.CharField(max_length=500,null=True)
77
category_description = models.CharField(max_length=500,null=True)
88
category_icon = models.CharField(max_length=100,null=True)
9-
9+
seo_url = models.CharField(max_length=500,null=True)
1010
class Meta:
1111
verbose_name_plural = "Kategoriler"
1212

Blog/sitemaps.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
from Blog.models import post
1+
from Blog.models import post,category
22
url_list = []
3-
db = post.objects.all()
4-
for i in db:
5-
url_list.append("/makale/"+i.seo_url)
6-
3+
post_db = post.objects.all()
4+
for i in post_db:
5+
url_list.append('/'+i.seo_url)
6+
category_db = category.objects.all()
7+
for i in category_db:
8+
url_list.append('/kategori/'+i.seo_url)
79
# sitemaps.py
810
from django.contrib import sitemaps
911
from django.urls import reverse

Blog/views.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,32 @@
77
def home(request):
88
"""Ana Sayfa"""
99
db = post.objects.order_by('?')[:6]
10+
last_db = post.objects.order_by()[:3]
1011
return render(request, 'profil.html', {
11-
'db': db
12+
'db': db,
13+
'last_db':last_db
1214
})
1315

1416

1517
def about(request):
1618
""" Hakkımda Sayfası """
17-
last_db = post.objects.order_by('?')[:3]
19+
last_db = post.objects.order_by()[:3]
1820
return render(request, 'about.html', {
1921
'last_db': last_db
2022
})
2123

2224

2325
def contact(request):
2426
""" İletişim Sayfası """
25-
last_db = post.objects.order_by('?')[:3]
27+
last_db = post.objects.order_by()[:3]
2628
return render(request, 'contact.html', {
2729
'last_db': last_db
2830
})
2931

3032

3133
def blog(request):
3234
""" Blog yazıların listelendiği sayfa"""
33-
last_db = post.objects.order_by('?')[:3]
35+
last_db = post.objects.order_by()[:3]
3436
db = post.objects.order_by()[:6]
3537
post_db = post.objects.all()
3638
category_db = category.objects.all()
@@ -45,7 +47,7 @@ def blog(request):
4547

4648
def page(request,id):
4749
""" Blog Sayfalaması """
48-
last_db = post.objects.order_by('?')[:3]
50+
last_db = post.objects.order_by()[:3]
4951
post_db = post.objects.all()
5052
category_db = category.objects.all()
5153
pages = Paginator(post_db,5)
@@ -63,7 +65,7 @@ def page(request,id):
6365

6466
def blog_details(request, slug):
6567
""" makale_details sayfası """
66-
last_db = post.objects.order_by('?')[:3]
68+
last_db = post.objects.order_by()[:3]
6769
category_db = category.objects.all()
6870
db = post.objects.filter(seo_url=slug)
6971
return render(request, 'blog_details.html', {
@@ -75,10 +77,10 @@ def blog_details(request, slug):
7577

7678
def category_view(request, category_names):
7779
""" category details sayfası """
78-
last_db = post.objects.order_by('?')[:3]
80+
last_db = post.objects.order_by()[:3]
7981
category_db_list = category.objects.all()
80-
category_db = category.objects.filter(category_name=str(category_names))
81-
post_db = post.objects.filter(category_list__category_name=category_names)
82+
category_db = category.objects.filter(seo_url=category_names)
83+
post_db = post.objects.filter(category_list__seo_url=category_names)
8284
pages = Paginator(post_db,5)
8385
return render(request, 'category.html', {
8486
'last_db': last_db,
@@ -89,12 +91,14 @@ def category_view(request, category_names):
8991
'category_names':category_names
9092
})
9193

94+
95+
9296
def category_page(request, category_names,id):
9397
""" category details sayfası """
94-
last_db = post.objects.order_by('?')[:3]
98+
last_db = post.objects.order_by()[:3]
9599
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)
100+
category_db = category.objects.filter(seo_url=category_names)
101+
post_db = post.objects.filter(category_list__seo_url=category_names)
98102
pages = Paginator(post_db,5)
99103
try:
100104
db = pages.page(id)

BlogProject/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
ALLOWED_HOSTS = []
2929

3030

31+
# site name
32+
web_site_name = 'http://127.0.0.1:8000'
33+
3134
# Application definition
3235

3336
INSTALLED_APPS = [

BlogProject/urls.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@
2828

2929
urlpatterns = [
3030
url(r'^admin/', admin.site.urls),
31-
url(r'^$', home, name='home'),
31+
url(r'^anasayfa/', home, name='home'),
3232
url(r'^hakkimda/', about, name='about'),
3333
url(r'^iletisim/', contact, name='contact'),
34-
url(r'^blog/', blog, name='blog'),
34+
url(r'^$', blog, name='blog'),
35+
url(r'^(?P<slug>[\w-]+)/$', blog_details, name='makale'),
36+
url(r'^kategori/(?P<category_names>[\w-]+)/(?P<id>\d+)$', category_page, name='category_page'),
37+
url(r'^kategori/(?P<category_names>[\w-]+)/$', category_view, name='category_view'),
3538
url(r'^kategori/(?P<category_names>\w+)/$', category_view, name='category_view'),
36-
url(r'^makale/(?P<slug>[\w-]+)/$', blog_details, name='makale'),
3739
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'),
3940
url(r'^humans.txt$', human, name='human'),
4041
url(r'^robots.txt$', robots, name='human'),
4142
url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps},name='django.contrib.sitemaps.views.sitemap')

db.sqlite3

1 KB
Binary file not shown.

templates/about.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,6 @@ <h4>Yeteneklerim</h4>
147147

148148
{% block last_content %}
149149
{% for i in last_db %}
150-
<a href="/makale/{{ i.seo_url }}"><i class="fa fa-share" aria-hidden="true"></i> {{ i.title }}</a><br/>
150+
<a href="/{{ i.seo_url }}"><i class="fa fa-share" aria-hidden="true"></i> {{ i.title }}</a><br/>
151151
{% endfor %}
152152
{% endblock %}

templates/base.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@
4141
<span class="icon-bar"></span>
4242
<span class="icon-bar"></span>
4343
</button>
44-
<a class="navbar-brand" href="{% url 'home' %}"><i class="fa fa-wheelchair-alt" aria-hidden="true"></i> Ali Yaman</a>
44+
<a class="navbar-brand" href="{% url 'blog' %}"><i class="fa fa-wheelchair-alt" aria-hidden="true"></i> Ali Yaman</a>
4545
</div>
4646
<div class="navbar-collapse collapse">
4747
<ul class="nav navbar-nav navbar-right">
48-
<li><a href="/">Ana Sayfa</a></li>
48+
<li><a href="/anasayfa">Ana Sayfa</a></li>
4949
<li><a href="/hakkimda/">Hakkımda</a></li>
50-
<li><a href="/blog">Blog</a></li>
50+
<li><a href="/">Blog</a></li>
5151
<li><a href="/iletisim">İletişim</a></li>
5252
{% block category %}{% endblock %}
5353
</ul>

templates/blog.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<a href="#" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Kategoriler <span class="caret"></span></a>
77
<ul class="dropdown-menu">
88
{% for i in category_db %}
9-
<li><a href="/kategori/{{ i.category_name }}">{{ i.category_name }}</a></li>
9+
<li><a href="/kategori/{{ i.seo_url }}">{{ i.category_name }}</a></li>
1010
{% endfor %}
1111
</ul>
1212
</li>
@@ -48,7 +48,7 @@
4848
<div class="list-group list-group">
4949
<h4 class="">Kategoriler</h4>
5050
{% for i in category_db %}
51-
<a href="/kategori/{{ i.category_name }}" class="list-group-item"><i class="{{ i.category_icon }}" aria-hidden="true"></i> {{ i.category_name }}</a>
51+
<a href="/kategori/{{ i.seo_url }}" class="list-group-item"><i class="{{ i.category_icon }}" aria-hidden="true"></i> {{ i.category_name }}</a>
5252
{% endfor %}
5353
</div>
5454
</div>
@@ -58,13 +58,13 @@ <h4 class="">Kategoriler</h4>
5858

5959
{% for i in db %}
6060
<div class="row">
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>
61+
<div class="col-sm-4"><a href="/{{ i.seo_url }}" class=""><img src="{{ web_site_name }}/media/{{ i.image }}" class="img-responsive"></a>
6262
</div>
6363
<div class="col-sm-8">
64-
<h3 class="title"><a href="/makale/{{ i.seo_url }}">{{ i.title }}</a></h3>
64+
<h3 class="title"><a href="/{{ i.seo_url }}">{{ i.title }}</a></h3>
6565

6666
{{ i.content | safe | truncatechars:210 }}
67-
<p class="text-muted"> <i class="fa fa-hashtag" aria-hidden="true"></i> Etiketler : <a href="/makale/{{ i.seo_url }}">{{ i.keywords }}</a></p>
67+
<p class="text-muted"> <i class="fa fa-hashtag" aria-hidden="true"></i> Etiketler : <a href="/{{ i.seo_url }}">{{ i.keywords }}</a></p>
6868

6969
</div>
7070
</div>
@@ -84,6 +84,6 @@ <h3 class="title"><a href="/makale/{{ i.seo_url }}">{{ i.title }}</a></h3>
8484
{% endblock %}
8585
{% block last_content %}
8686
{% for i in last_db %}
87-
<a href="/makale/{{ i.seo_url }}"><i class="fa fa-share" aria-hidden="true"></i> {{ i.title }}</a><br/>
87+
<a href="/{{ i.seo_url }}"><i class="fa fa-share" aria-hidden="true"></i> {{ i.title }}</a><br/>
8888
{% endfor %}
8989
{% endblock %}

templates/blog_details.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<a href="#" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Kategoriler <span class="caret"></span></a>
66
<ul class="dropdown-menu">
77
{% for i in category_db %}
8-
<li><a href="/kategori/{{ i.category_name }}">{{ i.category_name }}</a></li>
8+
<li><a href="/kategori/{{ i.seo_url }}">{{ i.category_name }}</a></li>
99
{% endfor %}
1010
</ul>
1111
</li>
@@ -29,13 +29,13 @@ <h3>{{ i.title }}</h3>
2929
</div>
3030
</div>
3131
<div class="row mt centered">
32-
<p><bt>Yazar : <span class="renk">Ali Yaman</span></bt> - <bt>Kategori: <a href="/kategori/{{ i.category_list.category_name }}">{{ i.category_list.category_name }}</a></bt> - <bt>Tarih: <span class="renk">{{ i.time }}</span></bt></p>
32+
<p><bt>Yazar : <span class="renk">Ali Yaman</span></bt> - <bt>Kategori: <a href="/kategori/{{ i.category_list.seo_url }}">{{ i.category_list.category_name }}</a></bt> - <bt>Tarih: <span class="renk">{{ i.time }}</span></bt></p>
3333
</div><!-- /row -->
3434
</div><!-- /container -->
3535
{% endfor %}
3636
{% endblock %}
3737
{% block last_content %}
3838
{% for i in last_db %}
39-
<a href="/makale/{{ i.seo_url }}"><i class="fa fa-share" aria-hidden="true"></i> {{ i.title }}</a><br/>
39+
<a href="/{{ i.seo_url }}"><i class="fa fa-share" aria-hidden="true"></i> {{ i.title }}</a><br/>
4040
{% endfor %}
4141
{% endblock %}

0 commit comments

Comments
 (0)