1 / 71

2012 06 18

2012 06 18 . The web framework for perfectionists with deadlines. django. KAIST PORTAL. SPARCS 홈페이지 bitbucket.org 대부분의 Trac System Google App Engine ……. and…. http://mashable.com/2011/07/26/startup-tools/. Django makes it easier to build better Web apps

hung
Télécharger la présentation

2012 06 18

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 20120618

  2. The web framework for perfectionists with deadlines django

  3. KAIST PORTAL

  4. SPARCS 홈페이지 bitbucket.org 대부분의 Trac System Google App Engine …… and…

  5. http://mashable.com/2011/07/26/startup-tools/

  6. Django makes it easier to build better Web apps More quickly, and with less code. django

  7. @Hodduci ARAra / Wheel 아제로스 행성오그리마 시 지혜의 골짜기 마을 SPARCS 10 / KAIST 10 호떡

  8. CGI vs. Django Why we use django? What is web?

  9. Request/response

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

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

  12. 우리가 만들어야 하는 것

  13. 서버님, http://ara.kaist.ac.kr 좀 보내주세요 INPUT을 받아 OUTPUT 출력하기 여기요 ㄲㄲ

  14. #include <iostream> using namespace std; int main() { cin >> input; (do something…) cout << output; return 0; } The simplest way

  15. #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; } = CGI

  16. 우리에겐 재겸신이Django가 있으니까요! Don’t reinvent the wheel

  17. Project / Application Basic structure

  18. Project & Application

  19. ! Project ‘tutorial’ with ‘helloworld’, ‘intro’ apps 오늘의 프로젝트

  20. 무작정 따라 해봅시다 Hello, World!

  21. ~ $ django-admin.py startproject tutorial ~ $ cd tutorial ~/tutorial $ ls manage.py tutorial ~/tutorial $ ls tutorial __init__.py settings.py urls.py wsgi.py

  22. tutorial/ manage.py tutorial/ __init__.py settings.py urls.py wsgi.py 프로젝트 관리 유틸리티 패키지 디렉토리 Empty file : Python package 구분자 각종 세팅이 들어있는 파일 URL 매핑을 하는 파일 WSGI entry point

  23. ~/tutorial $ python manage.py runserver 0.0.0.0:port 실습 중에는 20000~30000 사이 아무거나 잡아서 쓰세요. 혹시 누군가와 숫자가 겹친다면 그것은 운명의 장난~♥

  24. !!!

  25. 첫 번째 앱: Hello world!

  26. ~/tutorial $ python manage.py startapphelloworld ~/tutorial $ ls helloworld manage.py tutorial ~/tutorial $ lshelloworld __init__.py models.py tests.py views.py

  27. ~/tutorial $ cd helloworld ~/tutorial/helloworld $ vi views.py from django.http import HttpResponse # Create your views here. defhelloworld(request): return HttpResponse("Hello, World!") 1. View 작성하기

  28. ~/tutorial/helloworld $ cd ../tutorial ~/tutorial/tutorial $ vi urls.py … urlpatterns = patterns(‘’, url(r‘^helloworld/’, ‘helloworld.views.helloworld’), … 2. View의 함수에 대응되는 URL 만들기

  29. ~/tutorial/tutorial $ vi settings.py INSTALLED_APPS = ( …. ‘django.contrib.messages’, ‘helloworld’, ) 3. 추가된 App을 Project에 등록하기

  30. ~/tutorial $ python manage.py runserver 0.0.0.0:port http://bit.sparcs.org:12345/

  31. ~/tutorial $ python manage.py runserver 0.0.0.0:port http://bit.sparcs.org:12345/helloworld/

  32. Recursive URL Patterns Dynamic URL URL processing

  33. urls.py • /register/ 는 User 앱의register() 로 가시구요 • /login/ 는 User 앱의login()로 가시구요. • /write/ 는 Board 앱의write_article() 로 가세요! … urlpatterns = patterns(‘’, (r‘^register/’, ‘myproj.User.views.register’), (r‘^login/’, ‘myproj.User.views.login’), (r’^write/’, ‘myproj.Board.views.write_article’), )

  34. Urls.py == 이정표

  35. 서울에서 부산까지 가는데모든 가능한 길이 한 이정표에 있다면?

  36. urls.py • /user 는 User 앱으로가시구요 • /board 는 Board 앱으로 가세요. • 자세한 건 가보시면 압니다! … urlpatterns = patterns(‘’, (r‘^user/’, include(‘myproj.User.urls’)), (r’^board/’, include(‘myproj.Board.urls’)), )

  37. /user/urls.py • /user/register/ 는 register() 로 가시구요 • /user/login/ 는 login() 로 가세요. • 그 외엔 관심 없어요! 잘못 오셨네요! … urlpatterns = patterns(‘’, (r‘^register/’, ‘views.register’), (r‘^login/’, ‘views.login’), )

  38. 우리도 나눠봅시다

  39. ~/tutorial $ vi tutorial/urls.py … urlpatterns = patterns(‘’, (r‘^helloworld/’, include(‘helloworld.urls’)), …

  40. ~/tutorial $ cp tutorial/urls.py helloworld/ ~/tutorial $ vi helloworld/urls.py … urlpatterns = patterns(‘’, (r‘^$’, ‘helloworld.views.hello’)), …

  41. Tutorial/tutorial/urls.py … urlpatterns = patterns(‘’, (r‘^helloworld/’, include(‘helloworld.urls’)), … Tutorial/helloworld/urls.py … urlpatterns = patterns(‘’, (r‘^$’, ‘helloworld.views.helloworld’)), …

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

  43. Dynamic URL • 저 regExp에 맞는 URL을 read로 보내주세요. • 단, 각각 match된 부분을 read의 Parameter로 쓸 거에요! … urlpatterns = patterns(‘’, … (r'^([\w \[\]\.]+)/([\d]+)/$', ‘warara.board.views.read') … )

  44. Dynamic URL 만약 /garbage/3334343/ 라면 read(request, ‘garbage’, ‘3334343’) 을 호출한 것과 같게 동작 … urlpatterns = patterns(‘’, … (r'^([\w \[\]\.]+)/([\d]+)/$', ‘warara.board.views.read') … )

  45. 두 번째 앱: Intro

  46. 나는 ( ) ( )의 ( )이다!

  47. ~/tutorial $ cd intro ~/tutorial/intro $ vi 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, mimetype='text/html; charset=UTF-8') 1. View 작성하기

More Related