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
420
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
150
Vagrant 101
vigo
3
210
Yazılımcı Kimdir?
vigo
1
380
Other Decks in Programming
See All in Programming
GCCのプラグインを作る / I Made a GCC Plugin
shouth
1
150
Googleのテストサイズを活用したテスト環境の構築
toms74209200
0
270
Golang と Erlang
taiyow
8
1.9k
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
7
2.8k
CPython 인터프리터 구조 파헤치기 - PyCon Korea 24
kennethanceyer
0
240
飲食業界向けマルチプロダクトを実現させる開発体制とリアルな現状
hiroya0601
1
390
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
130
Modern Angular: Renovation for Your Applications
manfredsteyer
PRO
0
200
Server Driven Compose With Firebase
skydoves
0
400
PLoP 2024: The evolution of the microservice architecture pattern language
cer
PRO
0
1.6k
Importmapを使ったJavaScriptの 読み込みとブラウザアドオンの影響
swamp09
4
1.2k
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
0
150
Featured
See All Featured
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Scaling GitHub
holman
458
140k
The Language of Interfaces
destraynor
154
24k
Typedesign – Prime Four
hannesfritz
39
2.4k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
It's Worth the Effort
3n
183
27k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
Faster Mobile Websites
deanohume
304
30k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.6k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
13
1.9k
Why You Should Never Use an ORM
jnunemaker
PRO
53
9k
Code Review Best Practice
trishagee
64
17k
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 ?