Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Django
Search
Uğur Özyılmazel
February 27, 2016
Programming
4
420
Django
3.Programlama Dilleri, 2016
Karabük Üniversitesi'nde yaptığım Sunum
Uğur Özyılmazel
February 27, 2016
Tweet
Share
More Decks by Uğur Özyılmazel
See All by Uğur Özyılmazel
Idiomatic Go - Conventions over Configurations
vigo
2
210
Makefile değil, Rakefile
vigo
2
630
Bir Django Projesi : <Buraya RUBY ekleyin>
vigo
1
430
Ruby 101
vigo
1
89
Gündelik Hayatta GIT İpuçları
vigo
4
580
Bash 101
vigo
4
490
TDD - Test Driven Development
vigo
3
160
Vagrant 101
vigo
3
210
Yazılımcı Kimdir?
vigo
1
380
Other Decks in Programming
See All in Programming
イベント駆動で成長して委員会
happymana
1
340
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
3
690
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
1
300
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
2
1.2k
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
120
Micro Frontends Unmasked Opportunities, Challenges, Alternatives
manfredsteyer
PRO
0
110
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.2k
みんなでプロポーザルを書いてみた
yuriko1211
0
280
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
980
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
480
Tauriでネイティブアプリを作りたい
tsucchinoko
0
370
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
Featured
See All Featured
What's new in Ruby 2.0
geeforr
343
31k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
28
2k
The Invisible Side of Design
smashingmag
298
50k
The Cost Of JavaScript in 2023
addyosmani
45
6.8k
For a Future-Friendly Web
brad_frost
175
9.4k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Done Done
chrislema
181
16k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
Designing the Hi-DPI Web
ddemaree
280
34k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
How to train your dragon (web standard)
notwaldorf
88
5.7k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
Transcript
None
Az kod yazarak hızlı web uygulaması geliştirmeyi kolaylaştıran bir Python
kütüphanesi
Uğur “vigo” Özyılmazel vigo vigobronx
CRUD
Create Read Update Delete
INSERT INTO users (email, password) VALUES ('
[email protected]
', '12345') CREATE
SELECT * FROM users READ
UPDATE users SET email = '
[email protected]
' WHERE id = 1
UPDATE
DELETE FROM users WHERE id = 1 DELETE
None
Batteries included Pilleri de yanında
DATABASE ABSTRACT
Model View Template
Model Template View
Form
Admin Panel
Security
I18N / L10N / TZ
Authentication / Session
Caching
Email / File Upload
BLOG id, status, published_at, title, body
pip install django django-admin.py startproject pg16_django cd pg16_django/ python manage.py
migrate python manage.py createsuperuser python manage.py startapp blog
blog/ ├── migrations ├── __init__.py ├── admin.py ├── apps.py ├──
models.py ├── tests.py └── views.py
# -*- coding: utf-8 -*- from __future__ import unicode_literals from
django.db import models POST_STATUS = ( (0, u"Kapalı"), (1, u"Yayında"), ) class Post(models.Model): created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) status = models.IntegerField(choices=POST_STATUS, default=1,) published_date = models.DateTimeField() title = models.CharField(max_length=255) body = models.TextField() def __unicode__(self): return u"%s" % self.title
None
python manage.py makemigrations python manage.py migrate
operations = [ migrations.CreateModel( name='Post', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False,
verbose_name='ID')), ('created_at', models.DateTimeField( auto_now_add=True)), ('updated_at', models.DateTimeField( auto_now=True)), ('status', models.IntegerField(choices=[ (0, ‘Kapal\u0131'), (1, 'Yay\u0131nda')], default=1)), ('published_date', models.DateTimeField()), ('title', models.CharField(max_length=255)), ('body', models.TextField()), ], ), ]
Admin Panel
None
python manage.py runserver http://127.0.0.1:8000/admin/
None
None
class Post(models.Model): created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) status =
models.IntegerField(choices=POST_STATUS, default=1,) published_at = models.DateTimeField() title = models.CharField(max_length=255) body = models.TextField()
python manage.py makemigrations
Did you rename post.published_date to post.published_at (a DateTimeField)? [y/N] y
Migrations for 'blog': 0002_auto_20160224_1150.py: - Rename field published_date on post to published_at
None
VIEW ve TEMPLATE
CLASS BASED VIEW
CRUD create
class PostCreate(CreateView): model = Post template_name = 'post-add-update.html' fields =
['title', 'body', 'published_at'] initial = { 'published_at': datetime.datetime.now(), } success_url = reverse_lazy('post-list')
CRUD read
class PostDetail(DetailView): model = Post template_name = 'post-detail.html' def get_queryset(self):
qs = super(PostDetail, self).get_queryset() return qs.filter(status=1, pk=self.kwargs.get('pk', None))
CRUD update
class PostUpdate(UpdateView): model = Post template_name = 'post-add-update.html' fields =
['title', 'body'] success_url = reverse_lazy('post-list')
CRUD delete
class PostDelete(DeleteView): model = Post template_name = 'post-check-delete.html' success_url =
reverse_lazy('post-list')
TÜM KAYITLAR
class PostList(ListView): model = Post template_name = 'post-list.html' ordering =
['-published_at'] queryset = Post.objects.filter(status=1)
TEMPLATE
{% load staticfiles %} <!DOCTYPE html> <html lang="en"> <head> <meta
charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Kişisel Blog{% block html_title %}{% endblock %}</title> <link rel="stylesheet" href="{% static 'css/application.css' %}"> </head> <body> {% block content %}{% endblock %} </body> </html>
{% load staticfiles %} <!DOCTYPE html> <html lang="en"> <head> <meta
charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Kişisel Blog{% block html_title %}{% endblock %}</title> <link rel="stylesheet" href="{% static 'css/application.css' %}"> </head> <body> {% block content %}{% endblock %} </body> </html>
{% extends 'layout.html' %} {% load humanize %} {% block
html_title %} : Postlar{% endblock %} {% block content %} {% include "header.html" %} <div class="container"> <div class="row"> <div class="col-xs-12"> <ul class="list-unstyled post-list"> {% for post in object_list %} <li> <a title="Detaylar için tıkla" href="{{ post. <time pubdate datetime="{{ post.published_at| <p class="lead">{{ post.body|striptags|trunca </li> {% endfor %} </ul> <a class="btn btn-lg btn-primary" href="{% url 'post- </div> </div> </div> {% include "footer.html" %} {% endblock content %}
{% extends 'layout.html' %} {% load humanize %} {% block
html_title %} : Postlar{% endblock %} {% block content %} {% include "header.html" %} <div class="container"> <div class="row"> <div class="col-xs-12"> <ul class="list-unstyled post-list"> {% for post in object_list %} <li> <a title="Detaylar için tıkla" href="{{ post. <time pubdate datetime="{{ post.published_at| <p class="lead">{{ post.body|striptags|trunca </li> {% endfor %} </ul> <a class="btn btn-lg btn-primary" href="{% url 'post- </div> </div> </div> {% include "footer.html" %} {% endblock content %}
{% extends 'layout.html' %} {% load humanize %} {% block
html_title %} : Postlar{% endblock %} {% block content %} {% include "header.html" %} <div class="container"> <div class="row"> <div class="col-xs-12"> <ul class="list-unstyled post-list"> {% for post in object_list %} <li> <a title="Detaylar için tıkla" href="{{ post. <time pubdate datetime="{{ post.published_at| <p class="lead">{{ post.body|striptags|trunca </li> {% endfor %} </ul> <a class="btn btn-lg btn-primary" href="{% url 'post- </div> </div> </div> {% include "footer.html" %} {% endblock content %}
<ul class="list-unstyled post-list"> {% for post in object_list %} <li>
<a title="Detaylar için tıkla" href="{{ post.get_absolute_url }}">{{ post.title }}</a> <time pubdate datetime="{{ post.published_at|date:"c" }}" title="{{ post.published_at }}”> {{ post.published_at|naturaltime }}</time> <p class=“lead"> {{ post.body|striptags|truncatewords:20 }} </p> </li> {% endfor %} </ul> <a class="btn btn-lg btn-primary” href="{% url 'post-create' %}">Yeni Ekle</a>
{{ post.body|striptags|truncatewords:20 }}
{{ post.published_at|naturaltime }}
None
Kaynaklar
• http://tutorial.djangogirls.org/tr/ • https://docs.djangoproject.com/en/1.9/ • https://github.com/vigo/pg16_django • http://ccbv.co.uk/
http://media.djangopony.com/img/magic-pony-django-wallpaper.png Django Pony Resmi
Teşekkürler, sorular ?