정재성

Similar documents
widgets, events, layout loosely similar to Swing test browser, or plugin for testing with real browser on local system

Accelerating Information Technology Innovation

MIT AITI Python Software Development Lab DJ1:

Accelerating Information Technology Innovation

generates scaffolding/framework for models, views

Quoting Wikipedia, software

Lecture 10(-ish) Web [Application] Frameworks

Django: Views, Templates, and Sessions

Webdev: Building Django Apps. Ryan Fox Andrew Glassman MKE Python

Accelerating Information Technology Innovation

Accelerating Information Technology Innovation

Reminders. Full Django products are due next Thursday! CS370, Günay (Emory) Spring / 6

Rapid Development with Django and App Engine. Guido van Rossum May 28, 2008

Django Part II SPARCS 11 undead. Greatly Inspired by SPARCS 10 hodduc

The Django Web Framework Part II. Hamid Zarrabi-Zadeh Web Programming Fall 2013

CE419 Web Programming. Session 15: Django Web Framework

Moving to a Sustainable Web Development Environment for Library Web Applications

Django starting guide

Technology modeling. Ralf Lämmel Software Languages Team University of Koblenz-Landau

Django urls Django Girls Tutorial

Tomasz Szumlak WFiIS AGH 23/10/2017, Kraków

South Africa Templates.

Tangent MicroServices Documentation

MIT Global Startup Labs México 2013

DJOAuth2 Documentation

Lightweight. Django USING REST, WEBSOCKETS & BACKBONE. Julia Elman & Mark Lavin

Ninja Typers Web Application Design Document By Marvin Farrell C

Web Development with Python and Django. Mike Crute Mike Pirnat David Stanek

django-scaffold Documentation

Python. Django. (Web Application Framework - WAF) PyCharm. (Integration Development Environment - IDE)

Graphene Documentation

MapEntity Documentation

Django_template3d Documentation

Django by errors. Release 0.2. Sigurd Gartmann

Back-end development. Outline. Example API: Chatter. 1. Design an example API for Chatter. Tiberiu Vilcu.

web frameworks design comparison draft - please help me improve it focus on Model-View-Controller frameworks

django cms Documentation

Linguistic Architecture

Building a Django Twilio Programmable Chat Application

Django Standalone Apps

kiss.py Documentation

Django Deployment & Tips daybreaker

django-templation Documentation

Technology modeling with MegaL in software development

django-openid Documentation

SAURASHTRA UNIVERSITY

Django Web Framework: A Comprehensive Introduction and Step by Step Installation

Building APIs with Django and Django Rest Framework

Django design patterns Documentation

The syndication feed framework

alphafilter Documentation

django-messages Documentation

Diving into Big Data Workshop

django-facetools Documentation

Asynchronous WebSockets using Django

About the Tutorial. Audience. Prerequisites. Disclaimer & Copyright. Django

TailorDev Contact Documentation

Django Localized Recurrence Documentation

Django 1.0 Template Development

open-helpdesk Documentation

Technology modeling. Ralf Lämmel Software Languages Team University of Koblenz-Landau

LFC - Lightning Fast CMS Documentation

Mastering Django: Core

django-dajaxice Documentation

django-audiofield Documentation

wagtail-robots Documentation

django-intranet Documentation

Contents. 1. What is otree? 2. The Shell and Python. 3. Example: simple questionnaire. 4. Example: public goods game. 5. Test bots.

fragapy Documentation

django-model-report Documentation

Project OpenDSA Log Support Final Report

webkitpony Documentation

Django OAuth Toolkit Documentation

molly Documentation Release University of Oxford

Django PAM Documentation

Django Phantom Theme Documentation

Django IPRestrict Documentation

django-amp-tools Documentation Release latest

SAURASHTRA UNIVERSITY

Course Title: Python + Django for Web Application

canary Documentation Release 0.1 Branton K. Davis

First Django Admin Documentation

django-cms-search Documentation

Djam Documentation. Release Participatory Culture Foundation

Tango with Django. Chapter 1: Overview. 1. Overview. 2. The N tier architecture of web applications

COMMUNITY PARENTING PLATFORM

django-session-security Documentation

Unit 6 IoT Physical Servers, Cloud Offerings & IoT Case Studies. By Mahesh R. Sanghavi

django-oauth2-provider Documentation

The Design of Short Message Server with Linux Machine

colab Documentation Release 2.0dev Sergio Oliveira

Django Admin Sortable Documentation

Bricks Documentation. Release 1.0. Germano Guerrini

What You Need to Know about Python

Django-Mako-Plus Documentation

Getting Django Set Up Using a Functional Test

Accelerating Information Technology Innovation

Django Test Utils Documentation

Django MFA Documentation

A Sample Approach to your Project

Transcription:

건전지로달리는 쟝고세미나

정재성

Django

Web Framework

CGI

#!/usr/bin/env python import MySQLdb print "Content-Type: text/html\n" print "<html><head><title>books</title></head>" print "<body>" print "<h1>books</h1>" print "<ul>" connection = MySQLdb.connect(user='me', passwd='letmein', db='my_db') cursor = connection.cursor() cursor.execute("select name FROM books ORDER BY pub_date DESC LIMIT 10") for row in cursor.fetchall(): print "<li>%s</li>" % row[0] print "</ul>" print "</body></html>" connection.close()

Don t reinvent the wheel.

MVC

#!/usr/bin/env python import MySQLdb print "Content-Type: text/html\n" print "<html><head><title>books</title></head>" print "<body>" print "<h1>books</h1>" print "<ul>" connection = MySQLdb.connect(user='me', passwd='letmein', db='my_db') cursor = connection.cursor() cursor.execute("select name FROM books ORDER BY pub_date DESC LIMIT 10") for row in cursor.fetchall(): print "<li>%s</li>" % row[0] print "</ul>" print "</body></html>" connection.close()

models.py views.py urls.py template.html

# models.py (the database tables) from django.db import models class Book(models.Model): name = models.charfield(max_length=50) pub_date = models.datefield()

# views.py (the business logic) from django.shortcuts import render_to_response from models import Book def latest_books(request): book_list = Book.objects.order_by('- pub_date')[:10] return render_to_response('latest_books.html', {'book_list': book_list})

# urls.py (the URL configuration) from django.conf.urls.defaults import * import views urlpatterns = patterns('', (r'^latest/$', views.latest_books), )

# latest_books.html (the template) <html><head><title>books</title></head> <body> <h1>books</h1> <ul> {% for book in book_list %} <li>{{ book.name }}</li> {% endfor %} </ul> </body></html>

Loosely coupled

History

Install

Install Python

Install Django

http://www.djangoproject.com/

$ tar xzvf Django-*.tar.gz $ cd Django-* $ python setup.py install

Databases 코끼리, 나뭇잎 돌고래, 11g

Databases PostgreSQL, SQLite MySQL, Oracle

Starting a Project

$ django-admin.py startproject courserating

courserating/ init.py manage.py settings.py urls.py

Running DEV Server

$ python manage.py runserver

$ python manage.py runserver Validating models... 0 errors found Django version 1.2.1, using settings 'courserating.settings' Development server is running at http://127.0.0.1:8000/ Quit the server with CONTROL-C.

Views and URLconfs

First Django-Powered Page

# views.py from django.http import HttpResponse def hello(request): return HttpResponse("Hello world")

# urls.py from django.conf.urls.defaults import * from views import hello urlpatterns = patterns('', ('^hello/$', hello), )

# settings.py... ROOT_URLCONF = 'courserating.urls'...

1. Request /hello/ 2. Look at ROOT_URLCONF 3. Look at URLpatterns 4. Match then call the associated view function 5. The view function returns as HttpResponse 6. Convert HttpResponse to the proper HTTP response

Dynamic Content

>>> import datetime >>> now = datetime.datetime.now() >>> now datetime.datetime(2010, 6, 5, 1, 15, 20, 840166) >>> print now 2010-06-05 01:15:20.840166

# views.py from django.http import HttpResponse import datetime def current(request): now = datetime.datetime.now() html = "<html><body>now %s.</body></html>" % now return HttpResponse(html)

# urls.py from django.conf.urls.defaults import * from views import hello, current urlpatterns = patterns('', ('^hello/$', hello), ('^current/$', current), )

# urls.py from django.conf.urls.defaults import * from views import hello, current urlpatterns = patterns('', ('^hello/$', hello), ( ^current/$', current), ( ^another_current/$', current), )

Dynamic URLs

# urls.py urlpatterns = patterns('', ('^time/$', current), ('^time/plus/1/$', one_hour_ahead), ('^time/plus/2/$', two_hours_ahead), ('^time/plus/3/$', three_hours_ahead), ('^time/plus/4/$', four_hours_ahead), )

urlpatterns = patterns('', #... (r'^time/plus/\d+/$', hours_ahead), #... )

urlpatterns = patterns('', #... (r'^time/plus/(\d{1,2})/$', hours_ahead), #... )

# views.py def hours_ahead(request, offset): try: offset = int(offset) except ValueError: raise Http404() dt = datetime.datetime.now() + datetime.timedelta(hours=offset) html = "<html><body>in %s hour(s), it will be %s.</body></html>" % (offset, dt) return HttpResponse(html)

Templates

# views.py from django.http import HttpResponse import datetime def current(request): now = datetime.datetime.now() html = "<html><body>now %s.</body></html>" % now return HttpResponse(html)

>>> from django.conf import settings >>> settings.configure() >>> from django.template import Template, Context >>> t = Template('My ID is {{ name }}.') >>> c = Context({'name': hodduc'}) >>> print t.render(c) My ID is hodduc. >>> c = Context({'name': ' r4t5y6'}) >>> print t.render(c) My ID is r4t5y6. >>> print t <django.template.template object at 0x7fbb238c76d0>

>>> from django.template import Context >>> c = Context({"foo": "bar"}) >>> c['foo'] 'bar' >>> del c['foo'] >>> c['foo'] Traceback (most recent call last):... KeyError: 'foo' >>> c['newvariable'] = 'hello' >>> c['newvariable'] 'hello'

>>> from django.template import Template, Context >>> person = {'name': Yoona', 'age': 21'} >>> t = Template('{{ person.name.upper }} is {{ person.age }} years old.') >>> c = Context({'person': person}) >>> t.render(c) u YOONA is 21 years old.'

More Templates

{% if girlgeneration %} <strong>i Love You!</strong> {% else %} <p>then give it to dogs</p> {% if wondergirls %} <p>jimotmi</p> {% endif %} {% endif %}

{% for girl in girlgeneration %} <h1>{{ girl.name }}</h1> <ul> {% for a in girl.recent_solo_albums reversed %} <li>{{ a.name }}</li> {% endfor %} </ul> {% endfor %}

{% if girlgeneration == wondergirls %} <p>really?!</p> {% else %} <p>that s right!</p> {% endif %}

{% if variable > 1 %} {% if variable <= 1.23 %} {% if variable!= 'foo' %} {% if variable == "foo" %} {% if variable == True %} {% if variable == [1, 2, 3] %} {% if variable == {'key': 'value'} %}

{{ name lower }} {{ my_list first upper }} {{ my_list length }} {{ bio truncatewords:"30" }} {{ pub_date date:"f j, Y" }} {{ codes addslashes }} {{ html striptags }} {{ value default:"nothing" }}

{# World of Warcraft #} Hello

Templates in Views

# views.py from django.http import HttpResponse import datetime def current(request): now = datetime.datetime.now() html = "<html><body>now %s.</body></html>" % now return HttpResponse(html)

# views.py from django.template import Template, Context from django.http import HttpResponse import datetime def current(request): now = datetime.datetime.now() t = Template("<html><body>It is now {{ current_date }}.</body></html>") html = t.render(context({'current_date': now})) return HttpResponse(html)

# /templates/current.html <html><body>it is now {{ current_date }}.</body></html>

# views.py from django.template import Template, Context from django.http import HttpResponse import datetime def current(request): now = datetime.datetime.now() fp = open('/templates/current.html') t = Template(fp.read()) fp.close() html = t.render(context({'current_date': now})) return HttpResponse(html)

# settings.py TEMPLATE_DIRS = ( '/templates', )

# views.py from django.template.loader import get_template from django.template import Context from django.http import HttpResponse import datetime def current(request): now = datetime.datetime.now() t = get_template('current.html') html = t.render(context({'current_date': now})) return HttpResponse(html)

# views.py from django.shortcuts import render_to_response import datetime def current(request): now = datetime.datetime.now() return render_to_response('current.html', {'current_date': now})

Reusing Templates

# girlgeneration.html <html> <body> {% include 'members/tanggu.html' %}... </body> <html> # tanggu.html <p>romang</p>

# base.html <html> <head> <title>{% block title %}{% end block %}</title> </head> <body> <h1>kaist</h1> {% block content %}{% endblock %} {% block footer %} <p>daejeon</p> {% endblock %} </body> <html>

# dorm.html {% extends "base.html" %} {% block title %}Penalties{% endblock %} {% block content %}GG{% endblock %} # maru.html {% extends "base.html" %} {% block title %}Hell{% endblock %} {% block content %} Then give it to dogs!{% endblock %}

내일은

Models

Admin Sites

Forms

Users