Kathmandu
2016
NOW
is better
than
Why Python
• 4th Most popular language - IEEE survey
• Python is easy to use
• Powerful
• Versatile
• Choice for beginners and experts
Java & Python
TOP 10 PROGRAMMING LANGUAGES
• Java
• C
• C++
• Python
• C#
• R
• PHP
• JavaScript
• Ruby
• Matlab
Django!
Build with Python / Django
A framework
Not a CMS
Overview
Model View Controller
Fat Models
Templates
Thin views
Why Django is awesome
Why Django is awesome
Python
Python
Design Philosophy
- Less Code
- Quick development
- Don’t repeat yourself (DRY)
- Models
- URL design
- Template system
Community
from django.db import models
class Author(models.Model):
name= models.CharField(max_length=50)
email = models. EmailField()
class Book(models.Model):
author = models.ForeignKey(Author)
title= models.CharField(max_length=100)
price = models. DecimalField(decimal_places=2,
max_digits=11)
from django.conf.urls import patterns
from books.views import BooksListView, BooksDetailsView
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^books/$', BooksListView.as_view() ),
url(r'^books/(?P<pk>[0-9])/$', BooksDetailsView.as_view() ),
]
from django.http import HttpResponse
from django.views.generic.list import ListView
from django.views.generic.detail import DetailsView
from .models import Books
class BooksListView(ListView):
model = Books
class BooksListView (DetailsView):
model = Books
models.py
urls.py
views.py
Example, part 1
<html>
<head><title>Books List</title></head>
<body>
<ul>
{% for book in object_list %}
<li><a href="/books/{{ book.id }}"> {{ book.title }}</a> => {{ book.price }} | Author: {{ book.author.name }} </li>
{% endfor %}
</ul>
</body>
</html>
books_list.htmlExample, part 1
<html>
<head><title>Book Details</title></head>
<body>
<h1>{{ object.title }}</h1>
<p>By author: {{ object.author.name }} {{ object.author.email }},</p>
<ul>
{% for related_book in object.author.books.all %}
<li>{{ related_book }}</li>
{% endfor %}
</ul>
{% if book.number_of_pages > 100 %}
<p>This is a thick book.</p>
{% else %}
<p>You can read it in 2 hours.</p>
{% endif %}
</body>
</html>
books_detail.htmlExample, part 1
from django.contrib import admin
from .models import Book
class BooksAdmin(admin.ModelAdmin):
list_display = ['title', 'price', 'author']
admin.site.register(Books, BooksAdmin)
admin.py
Admin
Great tools
Happy coding
Resource
• https://jacobian.org/writing/why-django/
• https://www.youtube.com/watch?v=OjCz8yTloUI
• https://www.youtube.com/watch?v=n8KnFywpX
OE
• https://docs.djangoproject.com/en/1.9/
• https://www.python.org/
• https://www.shuup.com/en/blog/25-of-the-
most-popular-python-and-django-websites/
Thank You
Kishor Kumar Mahato
cyberkishor@gmail.com
@kishor_14
http://kishorkumarmahato.com.np
http://fb.com/kishrorkumar
https://np.linkedin.com/in/kishrorkumar
http://bitbucket.org/cyberkishor

Django girls-ktm

Editor's Notes

  • #11 Do you know what is python ? How many of you heard about Python ?
  • #12 "Eye-triple-E," stands for the Institute of Electrical and Electronics Engineers.
  • #20 What is framework ?
  • #21 What Is CMS ?
  • #31 Loose coupling¶ Less code Quick development