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
410
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
200
Makefile değil, Rakefile
vigo
2
620
Bir Django Projesi : <Buraya RUBY ekleyin>
vigo
1
410
Ruby 101
vigo
1
88
Gündelik Hayatta GIT İpuçları
vigo
4
570
Bash 101
vigo
4
480
TDD - Test Driven Development
vigo
3
150
Vagrant 101
vigo
3
210
Yazılımcı Kimdir?
vigo
1
370
Other Decks in Programming
See All in Programming
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
470
複数プロダクトの技術改善・クラウド移行に向き合うチームのフレキシブルなペア・モブプログラミングの実践 / Flexible Pair Programming And Mob Programming
honyanya
0
230
게임 개발하던 학생이이 세계에선 안드로이드 개발자?
pangmoo
0
110
Remix × Cloudflare Pages × Sentry 奮闘記 / remix-pages-sentry
nkzn
1
410
VS Code extension: ドラッグ&ドロップでファイルを並び替える
ttrace
0
170
UnJSで簡単に始めるCLIツール開発 / cli-tool-development-with-unjs
aoseyuu
2
290
tsconfig.jsonの最近の新機能 ファイルパス編
uhyo
6
1.7k
Modern Functional Fluent CFML REST by Luis Majano
ortus24
0
140
現場から考えるソフトウェアエンジニアリングの価値と実験
nomuson
1
120
Kubernetes上でOracle_Databaseの運用を楽にするOraOperatorの紹介
nnaka2992
0
150
Unlocking Python's Core Magic
leew
0
130
Kotlin Multiplatform at Stable and Beyond (Kotlin Vienna, October 2024)
zsmb
2
350
Featured
See All Featured
Gamification - CAS2011
davidbonilla
80
5k
Atom: Resistance is Futile
akmur
261
25k
Navigating Team Friction
lara
183
14k
A Modern Web Designer's Workflow
chriscoyier
692
190k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
167
49k
Writing Fast Ruby
sferik
626
60k
Automating Front-end Workflow
addyosmani
1365
200k
Making the Leap to Tech Lead
cromwellryan
131
8.8k
Music & Morning Musume
bryan
46
6.1k
Scaling GitHub
holman
458
140k
GitHub's CSS Performance
jonrohan
1030
450k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
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 ?