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
320
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
110
CSC509 Lecture 11
javiergs
PRO
0
180
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.2k
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
860
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
2
660
CSC509 Lecture 09
javiergs
PRO
0
140
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.1k
Quine, Polyglot, 良いコード
qnighy
4
640
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.3k
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
9
3.3k
Featured
See All Featured
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
The Cult of Friendly URLs
andyhume
78
6k
Designing Experiences People Love
moore
138
23k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Building Adaptive Systems
keathley
38
2.3k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
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 ?