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. View Slide

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

    View Slide

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

    View Slide

  4. CRUD

    View Slide

  5. Create
    Read
    Update
    Delete

    View Slide

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

    View Slide

  7. SELECT * FROM users
    READ

    View Slide

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

    View Slide

  9. DELETE FROM users WHERE id = 1
    DELETE

    View Slide

  10. View Slide

  11. Batteries included
    Pilleri de yanında

    View Slide

  12. DATABASE ABSTRACT

    View Slide

  13. Model View Template

    View Slide

  14. Model Template View

    View Slide

  15. Form

    View Slide

  16. Admin Panel

    View Slide

  17. Security

    View Slide

  18. I18N / L10N / TZ

    View Slide

  19. Authentication / Session

    View Slide

  20. Caching

    View Slide

  21. Email / File Upload

    View Slide

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

    View Slide

  23. 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 Slide

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

    View Slide

  25. # -*- 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 Slide

  26. View Slide

  27. python manage.py makemigrations
    python manage.py migrate

    View Slide

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

  29. Admin Panel

    View Slide

  30. View Slide

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

    View Slide

  32. View Slide

  33. View Slide

  34. 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 Slide

  35. python manage.py makemigrations

    View Slide

  36. 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 Slide

  37. View Slide

  38. VIEW ve TEMPLATE

    View Slide

  39. CLASS BASED VIEW

    View Slide

  40. CRUD
    create

    View Slide

  41. 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 Slide

  42. CRUD
    read

    View Slide

  43. 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 Slide

  44. CRUD
    update

    View Slide

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

    View Slide

  46. CRUD
    delete

    View Slide

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

    View Slide

  48. TÜM KAYITLAR

    View Slide

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

    View Slide

  50. TEMPLATE

    View Slide

  51. {% load staticfiles %}






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



    {% block content %}{% endblock %}


    View Slide

  52. {% load staticfiles %}






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



    {% block content %}{% endblock %}


    View Slide

  53. {% 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 Slide

  54. {% 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 Slide

  55. {% 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 Slide


  56. {% 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 Slide

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

    View Slide

  58. {{ post.published_at|naturaltime }}

    View Slide

  59. View Slide

  60. Kaynaklar

    View Slide

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

    View Slide

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

    View Slide

  63. Teşekkürler, sorular ?

    View Slide