Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Django

 Django

3.Programlama Dilleri, 2016
Karabük Üniversitesi'nde yaptığım Sunum

Uğur Özyılmazel

February 27, 2016
Tweet

More Decks by Uğur Özyılmazel

Other Decks in Programming

Transcript

  1. Az kod yazarak hızlı web uygulaması geliştirmeyi
    kolaylaştıran bir Python kütüphanesi

    View full-size slide

  2. Uğur “vigo” Özyılmazel
    vigo
    vigobronx

    View full-size slide

  3. Create
    Read
    Update
    Delete

    View full-size slide

  4. INSERT INTO users (email, password)
    VALUES ('[email protected]', '12345')
    CREATE

    View full-size slide

  5. SELECT * FROM users
    READ

    View full-size slide

  6. UPDATE users SET email = '[email protected]'
    WHERE id = 1
    UPDATE

    View full-size slide

  7. DELETE FROM users WHERE id = 1
    DELETE

    View full-size slide

  8. Batteries included
    Pilleri de yanında

    View full-size slide

  9. DATABASE ABSTRACT

    View full-size slide

  10. Model View Template

    View full-size slide

  11. Model Template View

    View full-size slide

  12. I18N / L10N / TZ

    View full-size slide

  13. Authentication / Session

    View full-size slide

  14. Email / File Upload

    View full-size slide

  15. BLOG
    id, status, published_at, title, body

    View full-size slide

  16. 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

    View full-size slide

  17. blog/
    ├── migrations
    ├── __init__.py
    ├── admin.py
    ├── apps.py
    ├── models.py
    ├── tests.py
    └── views.py

    View full-size slide

  18. # -*- 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

    View full-size slide

  19. python manage.py makemigrations
    python manage.py migrate

    View full-size slide

  20. 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()),
    ],
    ),
    ]

    View full-size slide

  21. python manage.py runserver
    http://127.0.0.1:8000/admin/

    View full-size slide

  22. 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()

    View full-size slide

  23. python manage.py makemigrations

    View full-size slide

  24. 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

    View full-size slide

  25. VIEW ve TEMPLATE

    View full-size slide

  26. CLASS BASED VIEW

    View full-size slide

  27. 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')

    View full-size slide

  28. 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))

    View full-size slide

  29. class PostUpdate(UpdateView):
    model = Post
    template_name = 'post-add-update.html'
    fields = ['title', 'body']
    success_url = reverse_lazy('post-list')

    View full-size slide

  30. class PostDelete(DeleteView):
    model = Post
    template_name = 'post-check-delete.html'
    success_url = reverse_lazy('post-list')

    View full-size slide

  31. TÜM KAYITLAR

    View full-size slide

  32. class PostList(ListView):
    model = Post
    template_name = 'post-list.html'
    ordering = ['-published_at']
    queryset = Post.objects.filter(status=1)

    View full-size slide

  33. {% load staticfiles %}






    Kişisel Blog{% block html_title %}{% endblock %}



    {% block content %}{% endblock %}


    View full-size slide

  34. {% load staticfiles %}






    Kişisel Blog{% block html_title %}{% endblock %}



    {% block content %}{% endblock %}


    View full-size slide

  35. {% extends 'layout.html' %}
    {% load humanize %}
    {% block html_title %} : Postlar{% endblock %}
    {% block content %}
    {% include "header.html" %}




    {% for post in object_list %}

    {{ post.body|striptags|trunca

    {% endfor %}

    {% endblock content %}

    View full-size slide

  36. {% extends 'layout.html' %}
    {% load humanize %}
    {% block html_title %} : Postlar{% endblock %}
    {% block content %}
    {% include "header.html" %}




    {% for post in object_list %}

    {{ post.body|striptags|trunca

    {% endfor %}

    {% endblock content %}

    View full-size slide

  37. {% extends 'layout.html' %}
    {% load humanize %}
    {% block html_title %} : Postlar{% endblock %}
    {% block content %}
    {% include "header.html" %}




    {% for post in object_list %}

    {{ post.body|striptags|trunca

    {% endfor %}

    {% endblock content %}

    View full-size slide


  38. {% for post in object_list %}

    href="{{ post.get_absolute_url }}">{{ post.title }}
    title="{{ post.published_at }}”>
    {{ post.published_at|naturaltime }}

    {{ post.body|striptags|truncatewords:20 }}


    {% endfor %}

    Yeni Ekle

    View full-size slide

  39. {{ post.body|striptags|truncatewords:20 }}

    View full-size slide

  40. {{ post.published_at|naturaltime }}

    View full-size slide

  41. • http://tutorial.djangogirls.org/tr/
    • https://docs.djangoproject.com/en/1.9/
    • https://github.com/vigo/pg16_django
    • http://ccbv.co.uk/

    View full-size slide

  42. http://media.djangopony.com/img/magic-pony-django-wallpaper.png
    Django Pony Resmi

    View full-size slide

  43. Teşekkürler, sorular ?

    View full-size slide