Django

Similar documents
Portal_9iAS.ppt [읽기 전용]

Relational Model

<C0CCBCBCBFB52DC1A4B4EBBFF82DBCAEBBE7B3EDB9AE2D D382E687770>

MPLAB C18 C

Microsoft PowerPoint - web-part03-ch19-node.js기본.pptx


DocsPin_Korean.pages

LXR 설치 및 사용법.doc

Analytics > Log & Crash Search > Unity ios SDK [Deprecated] Log & Crash Unity ios SDK. TOAST SDK. Log & Crash Unity SDK Log & Crash Search. Log & Cras

PowerPoint 프레젠테이션

DE1-SoC Board

Multi Channel Analysis. Multi Channel Analytics :!! - (Ad network ) Report! -! -!. Valuepotion Multi Channel Analytics! (1) Install! (2) 3 (4 ~ 6 Page

0125_ 워크샵 발표자료_완성.key

02 C h a p t e r Java

C프로-3장c03逞풚

chapter4

4. #include <stdio.h> #include <stdlib.h> int main() { functiona(); } void functiona() { printf("hihi\n"); } warning: conflicting types for functiona

Polly_with_Serverless_HOL_hyouk

Stage 2 First Phonics

초보자를 위한 C++

No Slide Title

Interstage5 SOAP서비스 설정 가이드

Week13

K7VT2_QIG_v3

Dialog Box 실행파일을 Web에 포함시키는 방법

Page 2 of 5 아니다 means to not be, and is therefore the opposite of 이다. While English simply turns words like to be or to exist negative by adding not,

슬라이드 1

<443A5C4C C4B48555C B3E25C32C7D0B1E25CBCB3B0E8C7C1B7CEC1A7C6AE425CC0E7B0EDB0FCB8AE5C53746F636B5F4D616E D656E74732E637070>

Building Mobile AR Web Applications in HTML5 - Google IO 2012

6주차.key

untitled

슬라이드 1

소개 TeraStation 을 구입해 주셔서 감사합니다! 이 사용 설명서는 TeraStation 구성 정보를 제공합니다. 제품은 계속 업데이트되므로, 이 설명서의 이미지 및 텍스트는 사용자가 보유 중인 TeraStation 에 표시 된 이미지 및 텍스트와 약간 다를 수

C++ Programming

playnode.key

휠세미나3 ver0.4

Mobile Service > IAP > Android SDK [ ] IAP SDK TOAST SDK. IAP SDK. Android Studio IDE Android SDK Version (API Level 10). Name Reference V

Web Scraper in 30 Minutes 강철

PowerPoint 프레젠테이션

DIY 챗봇 - LangCon

HTML5* Web Development to the next level HTML5 ~= HTML + CSS + JS API

FMX M JPG 15MB 320x240 30fps, 160Kbps 11MB View operation,, seek seek Random Access Average Read Sequential Read 12 FMX () 2

본문01

chapter1,2.doc

Solaris Express Developer Edition

CD-RW_Advanced.PDF

Microsoft PowerPoint - [2009] 02.pptx

1217 WebTrafMon II

요약 1

PowerPoint 프레젠테이션

Eclipse 와 Firefox 를이용한 Javascript 개발 발표자 : 문경대 11 년 10 월 26 일수요일

28 THE ASIAN JOURNAL OF TEX [2] ko.tex [5]

ETL_project_best_practice1.ppt

Microsoft PowerPoint SDK설치.HelloAndroid(1.5h).pptx

Social Network

C++ Programming

untitled

APOGEE Insight_KR_Base_3P11

서현수

3장

MAX+plus II Getting Started - 무작정따라하기

Domino Designer Portal Development tools Rational Application Developer WebSphere Portlet Factory Workplace Designer Workplace Forms Designer

쉽게 풀어쓴 C 프로그래밍

USER GUIDE

13주-14주proc.PDF

PowerPoint 프레젠테이션

ibmdw_rest_v1.0.ppt

I T C o t e n s P r o v i d e r h t t p : / / w w w. h a n b i t b o o k. c o. k r

PowerPoint 프레젠테이션

신림프로그래머_클린코드.key

PowerPoint 프레젠테이션

Microsoft PowerPoint Android-SDK설치.HelloAndroid(1.0h).pptx

ORANGE FOR ORACLE V4.0 INSTALLATION GUIDE (Online Upgrade) ORANGE CONFIGURATION ADMIN O

F120S_(Rev1.0)_1130.indd

Microsoft PowerPoint - additional01.ppt [호환 모드]

PowerPoint 프레젠테이션

C++-¿Ïº®Çؼ³10Àå

,,,,,, (41) ( e f f e c t ), ( c u r r e n t ) ( p o t e n t i a l difference),, ( r e s i s t a n c e ) 2,,,,,,,, (41), (42) (42) ( 41) (Ohm s law),

HTML5가 웹 환경에 미치는 영향 고 있어 웹 플랫폼 환경과는 차이가 있다. HTML5는 기존 HTML 기반 웹 브라우저와의 호환성을 유지하면서도, 구조적인 마크업(mark-up) 및 편리한 웹 폼(web form) 기능을 제공하고, 리치웹 애플리케이 션(RIA)을

FileMaker 15 WebDirect 설명서

untitled

Page 2 of 6 Here are the rules for conjugating Whether (or not) and If when using a Descriptive Verb. The only difference here from Action Verbs is wh

50_1953.pdf

Intro to Servlet, EJB, JSP, WS

초보자를 위한 ASP.NET 2.0

PowerPoint 프레젠테이션

교육2 ? 그림

ecorp-프로젝트제안서작성실무(양식3)

Remote UI Guide

Output file

컴퓨터과학과 교육목표 컴퓨터과학과의 컴퓨터과학 프로그램은 해당분야 에서 학문적 기술을 창의적으로 연구하고 산업적 기술을 주도적으로 개발하는 우수한 인력을 양성 함과 동시에 직업적 도덕적 책임의식을 갖는 IT인 육성을 교육목표로 한다. 1. 전공 기본 지식을 체계적으로

C H A P T E R 2

Sena Technologies, Inc. HelloDevice Super 1.1.0

3. 1 포인터란 3. 2 포인터변수의선언과사용 3. 3 다차원포인터변수의선언과사용 3. 4 주소의가감산 3. 5 함수포인터

Microsoft Word - KSR2014S042

untitled

Modern Javascript

untitled

PWR PWR HDD HDD USB USB Quick Network Setup Guide xdsl/cable Modem PC DVR 1~3 1.. DVR DVR IP xdsl Cable xdsl Cable PC PC DDNS (

슬라이드 1

Transcription:

Django Part I 2015-05-25 SPARCS 11 undead Greatly Inspired by SPARCS 10 hodduc

중간중간 GitHub 링크가있으니코드가필요하면참고하세요!

Django The web framework for perfectionists with deadlines. Django makes it easier to build better Web apps more quickly and with less code.

Websites Built with Django

Websites Built with Django

Websites Built with Django

Websites Built with Django

Websites Built with Django

Websites Built with Django

Django as a Web Framework 웹이란무엇일까?

Django as a Web Framework 웹이란무엇일까? HTTP request 와 HTTP response 의집합

Request: ara.kaist.ac.kr Response: 200 OK Client Server

Request: ara.kaist.ac.kr Response: 200 OK Client Server

Know What You Know Front end programming Web Application HTML5 CSS3 JavaScript jquery Bootstrap (a ready-to-serve HTML5/CSS3/JavaScript) Mobile Application Android ios

User Scenario

User Scenario User Clicks. What then?

Know What You Don t Know Back end programming Server Processing incoming requests (from user) Return response (to user) Database Save user interactions Logging

Know What You Don t Know Back end programming Server Processing incoming requests (from user) Return response (to user) Database Save user interactions Logging

Give an Output for an Input!

How? #include <iostream> using namespace std; int main() { cin >> input; (do something ) cout << output; } return 0;

How? CGI #include <stdio.h> #include <stdlib.h> int main(void) { char *data; long m,n; printf("%s%c%c\n", "Content-Type:text/html;charset=iso-8859-1",13,10); printf("<title>multiplication results</title>\n"); printf("<h3>multiplication results</h3>\n"); data = getenv("query_string"); if(data == NULL) printf("<p>error! Error in passing data from form to script."); else if(sscanf(data,"m=%ld&n=%ld",&m,&n)!=2) printf("<p>error! Invalid data. Data must be numeric."); else printf("<p>the product of %ld and %ld is %ld.",m,n,m*n); return 0; }

Don t Reinvent the Wheel 있는건그냥가져다씁시다. 또또칸애들이이미잘만들어뒀으니까요.

Let the Django Begin

Basic Structure Project and Applications

Basic Structure Django 웹어플리케이션은 project 와 app 으로구성되어있다.

ara board sysop account message mobile.. otl accounts dictionary groups timetable favorites..

Practice: Project tutorial With helloworld, intro apps

Before You Start Any Python Project ~/ $ virtualenv env ~/ $ source env/bin/activate # If a requirements.txt exists ~/ $ pip install -r requirements.txt (env) ~/ $

Before You Start Any Python Project ~/ $ virtualenv env ~/ $ source env/bin/activate # If a requirements.txt exists ~/ $ pip install -r requirements.txt (env) ~/ $ (env) ~/ $ deactivate # When you are done

Start a Django Project (env) ~/ $ pip install django # Django version 1.8.2 installed as of 2015-05-24. (env) ~/ $ django-admin startproject tutorial (env) ~/ $ cd tutorial (env) ~/tutorial $ ls manage.py tutorial

Start a Django Project env/.. tutorial/ manage.py tutorial/ init.py settings.py urls.py wsgi.py # Python virtual environment directory # Django project directory # Django project manage utility # Django default package directory # Empty file: python package identifier # File for Django settings # File for URL mapping # WSGI entry point

Start a Django Project (env) ~/tutorial $ python manage.py runserver 0.0.0.0:PORT_NUMBER # PORT_NUMBER in range 0 ~ 65535 # 0 ~ 9999 preoccupied by system. # (Which means, DON t USE THEM!!)

Start a Django Project View Code: Github.com

First App: Hello, World!

Creating a Django App (env) ~/tutorial $ python manage.py startapp helloworld (env) ~/tutorial $ ls helloworld manage.py tutorial (env) ~/tutorial $ ls helloworld init.py admin.py migrations models.py tests.py views.py

Add App to Project (env) ~/tutorial $ vi tutorial/settings.py INSTALLED_APPS = ( django.contrib.staticfiles, helloworld, )

Writing a View File (env) ~/tutorial $ vi helloworld/views.py from django.http import HttpResponse # Create your views here. def helloworld(request): return HttpResponse( Hello, World! )

Map a URL for a View Function (env) ~/tutorial $ vi tutorial/urls.py urlpatterns = [ url(r ^admin/, include(admin.site.urls)), url(r ^helloworld/, helloworld.views.helloworld ), ]

Run Server Again (env) ~/tutorial $ python manage.py runserver 0.0.0.0:PORT_NUMBER

Run Server Again (env) ~/tutorial $ python manage.py runserver 0.0.0.0:PORT_NUMBER View Code: Github.com

Understanding urls.py

Role of urls.py 이정표로써 urls.py Request 가발생했다! 여긴어디? 난누구? urls.py: 당황하지말고어디어디로가서이함수를실행시켜보세요.

Role of urls.py url(r ^helloworld/, helloworld.views.helloworld ), helloworld/ 요청이들어왔네요? helloworld app 안의 views.py 를열어보시고 helloworld() 라는함수를실행시키세요!

Application of urls.py 여러앱으로구성된프로젝트에서작업하고있다면? /main/view/ : 메인앱의뷰함수에뷰로가세요 /board/list/ : 보드앱의뷰함수에리스트로가세요 /board/new/ : 보드앱의뷰함수의리스트로가세.. 요 bb /board/edit/ : 보드앱의뷰함수의에딧으로가세요ㅠㅠㅠ /session/login/ : 세션앱의뷰함수의 : 으앙아몰랑ㅠㅠ

Application of urls.py 불쌍한 urls.py 짱을위해코드를모듈화합시다. /main/view/ : 메인앱이시네요? 메인앱의담당자한테 rr /board/list/ : 보드앱이시네요? 보드앱의담당자한테 rr /board/new/ : 너도보드앱한테가세요 /board/edit/ : 너도보드앱한테가시고그다음은아몰랑 /session/login/ : 세션앱의담당자한테가면걔가알려줄거임 /wrong_request/ : 넌누구세요? 안사요관심없어요

URL Routing (env) ~/tutorial $ cp tutorial/urls.py helloworld/ (env) ~/tutorial $ ls helloworld/ init.py admin.py migrations models.py tests.py urls.py views.py

URL Routing (env) ~/tutorial $ vi tutorial/urls.py urlpatterns = [ url(r ^admin/, include(admin.site.urls)), url(r ^helloworld/, helloworld.views.helloworld ), ]

URL Routing (env) ~/tutorial $ vi tutorial/urls.py urlpatterns = [ url(r ^admin/, include(admin.site.urls)), url(r ^helloworld/, helloworld.views.helloworld ), url(r ^helloworld/, include( helloworld.urls )), ]

URL Routing (env) ~/tutorial $ vi helloworld/urls.py urlpatterns = [ url(r ^admin/, include(admin.site.urls)), url(r ^helloworld/, helloworld.views.helloworld ), ]

URL Routing (env) ~/tutorial $ vi helloworld/urls.py urlpatterns = [ url(r ^admin/, include(admin.site.urls)), url(r ^helloworld/, helloworld.views.helloworld ), url(r ^$, helloworld.views.helloworld ), ]

Add Another View Function (env) ~/tutorial $ vi helloworld/views.py def helloworld(request): return HttpResponse( Hello, World! ) def introduce(request): return HttpResponse( This is Shavakan, 24 years old, from Zul jin, Azeroth. )

Add Another View Function (env) ~/tutorial $ vi helloworld/urls.py urlpatterns = [ url(r ^$, helloworld.views.helloworld ), url(r ^introduce/, helloworld.views.introduce ), ]

Add Another View Function (env) ~/tutorial $ python manage.py runserver 0.0.0.0:PORT_NUMBER View Code: Github.com

Add Another App (env) ~/tutorial $ python manage.py startapp intro (env) ~/tutorial $ vi tutorial/settings.py INSTALLED_APPS = ( django.contrib.staticfiles, helloworld, )

Add Another App (env) ~/tutorial $ python manage.py startapp intro (env) ~/tutorial $ vi tutorial/settings.py INSTALLED_APPS = ( django.contrib.staticfiles, helloworld, intro, )

Add Another App (env) ~/tutorial $ cp tutorial/urls.py intro/ (env) ~/tutorial $ vi tutorial/urls.py urlpatterns = [ url(r ^admin/, include(admin.site.urls)), url(r ^helloworld/, include( helloworld.urls )), ]

Add Another App (env) ~/tutorial $ cp tutorial/urls.py intro/ (env) ~/tutorial $ vi tutorial/urls.py urlpatterns = [ url(r ^admin/, include(admin.site.urls)), url(r ^helloworld/, include( helloworld.urls )), url(r ^intro/, include( intro.urls )), ]

Add Another App (env) ~/tutorial $ vi intro/views.py # -*- coding: utf-8 -*- from django.http import HttpResponse def home(request): return HttpResponse( /intro/ 스팍스 /( 자기학번 )/( 자기이름 ) 으로가주세요! )

Add Another App (env) ~/tutorial $ vi intro/urls.py urlpatterns = [ url(r ^admin/, include(admin.site.urls)), url(r ^helloworld/, include( helloworld.urls )), url(r ^$, intro.views.home ), ]

Add Another App (env) ~/tutorial $ python manage.py runserver 0.0.0.0:PORT_NUMBER

나는자바계의김정일이다! / K.H.L. 으아ㅏ아ㅏㅏㅏㅏㅏㅏㅏㅏ대포동발사!! /board/garbages/123456 아라개발팀에카와이한디자이너님이계시다던데사실인가요 / 호떡 진실은저너머에 /board/qanda/654321 여자친구와데이트후기 / qwertyasdf /board/love/1048576 매번바뀌는 URL 규칙 참고 : 픽션입니다 ^^

Dynamic URL URL pattern 은정규식으로표현한다. 모르면공부하세요 뭔줄알고필요할때찾아쓸수있는정도면됨 urlpatterns = patterns(, (r'^([\w \[\]\.]+)/([\d]+)/$', warara.board.views.read') )

Dynamic URL 만약 /garbage/3334343/ 이라면 read(request, garbage, 3334343 ) 함수호출과동일하게동작 urlpatterns = patterns(, (r'^([\w \[\]\.]+)/([\d]+)/$', warara.board.views.read') )

Write View Function for Dynamic URL (env) ~/tutorial $ vi intro/views.py # -*- coding: utf-8 -*- from django.http import HttpResponse def me(request, city, town, name): s = u" 나는 %s %s의 %s이다!" % (city, town, name) return HttpResponse(s)

Write Dynamic URL Handler (env) ~/tutorial $ vi intro/urls.py urlpatterns = [ url(r ^$, intro.views.home ), url(r'^([^/]+)/([^/]+)/([^/]+)/', 'intro.views.me'), ]

Run Server With Dynamic URL (env) ~/tutorial $ python manage.py runserver 0.0.0.0:PORT_NUMBER View Code: Github.com

Next Time: All About Template