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
430
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
220
Makefile değil, Rakefile
vigo
2
640
Bir Django Projesi : <Buraya RUBY ekleyin>
vigo
1
440
Ruby 101
vigo
1
95
Gündelik Hayatta GIT İpuçları
vigo
4
590
Bash 101
vigo
4
490
TDD - Test Driven Development
vigo
3
160
Vagrant 101
vigo
3
220
Yazılımcı Kimdir?
vigo
1
390
Other Decks in Programming
See All in Programming
Monixと常駐プログラムの勘どころ / Scalaわいわい勉強会 #4
stoneream
0
280
HTTP compression in PHP and Symfony apps
dunglas
2
1.7k
20年もののレガシープロダクトに 0からPHPStanを入れるまで / phpcon2024
hirobe1999
0
500
責務を分離するための例外設計 - PHPカンファレンス 2024
kajitack
6
1.1k
クリエイティブコーディングとRuby学習 / Creative Coding and Learning Ruby
chobishiba
0
3.9k
Zoneless Testing
rainerhahnekamp
0
120
CSC305 Lecture 26
javiergs
PRO
0
140
今年一番支援させていただいたのは認証系サービスでした
satoshi256kbyte
1
260
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
210
PHPとAPI Platformで作る本格的なWeb APIアプリケーション(入門編) / phpcon 2024 Intro to API Platform
ttskch
0
260
Spatial Rendering for Apple Vision Pro
warrenm
0
110
PSR-15 はあなたのための ものではない? - phpcon2024
myamagishi
0
130
Featured
See All Featured
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Raft: Consensus for Rubyists
vanstee
137
6.7k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
YesSQL, Process and Tooling at Scale
rocio
169
14k
Scaling GitHub
holman
458
140k
Imperfection Machines: The Place of Print at Facebook
scottboms
266
13k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.3k
A Philosophy of Restraint
colly
203
16k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
810
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 ?