프로그래밍 156

Python에서 Open API 호출하기

Rest API를 호출하기여러가지 라이브러리 (urllib2, httplib2)등을 체크해봤으나, https 를 가장 쉽게 호출할 수 있고, 사용하기 편한것은 requests라는 것이 가장 편리함 http://www.python-requests.org/en/latest/user/quickstart/#make-a-request 에서 curl 로 다운로드 하고 설치해서 사용 위는 도스창을 이용해서 간단하게 https로 dna.daum.net을 호출한 코드인데, 리턴값이 한글이라서 그런지. cp949 encode 에러가 남. (이건 나중에 수정해야 할거 같고) 기타 참고 자료 (아래) 참고 : API 호출 하기https://dna.daum.net/tools/python/tutorial SSL 사용하기urlli..

Django에서 static file (css,img 사용하기)

django는 모듈화가 잘된건지. 웹개발에 최적화 된건지여하간, tomcat처럼 디렉토리에 이미지나 CSS를 넣는다고 찾아지지 않는다. (html) templates 처럼 특정 디렉토리를 생성하고 setting.py 파일에 지정해줘야 한다 setting.py에서STATIC_URL = '/static/' 해주고 각 app 디렉토리 밑에 /static이란 디렉토리를 만들어준다.사용할 때는 load staticfiles를 불러준후에 경로를 다음과 같이 지정해주면 된다. {% load staticfiles %}this is group home ※ static file 경로 지정 방법 -https://docs.djangoproject.com/en/1.6/howto/static-files/

Django Template

Django의 MVC 구조 원본- littlegreenriver.comTemplate 란? Template은 쉽게 이야기 하면 jsp 파일과 같다고 보면된다.template은 string으로 파일에서 로딩할 수 도 있고 몇개의 notation을 통해서 구성된다.마치 JSP의 처럼time.html 파일이 다음과 같을때 current time is {{ current_time }} 이는 current time is (JSP에서)와 같은 의미라고 보면된다.실제 view 모듈에서 이 템플릿을 렌더링 하는데, 이때, tempalte에 있는 인자들을 대입한다. template = loader.get_template('time.html') current_time = datetime.datetime.now() cont..

Django Hello World

http://www.djangobook.com/en/2.0/chapter03.htmlDjango 설치후 django-admin.py startprojec Yurryt로 사이트 만들고 (Yurry 라는 프로젝트가 만들어짐)※ 참고 : Yurry 디렉토리안에는 urls.py, settings.py,_init_.py 등의 파일이 들어 있음. ../Yurry에 manage.py 파일등이 들어 있음Yurry/views.py 라는 파일을 만듬from django.http import HttpResponse def hello(request): return HttpResponse("Hello world")간단하게 Hello World를 Print Out하는 코드그 다음 Yurry/urls.py에from django.c..

Spring Batch 개념 정리

Spring Batch의 주요 개념 Job하나의 배치 작업을 정의. 예를 들어 "API 서버의 사용로그 테이블의 데이타를 로그 분석 시스템으로 옮기는 배치"Job Instance배치가 실제 실행되면, 각각의 실행을 Instance라고 한다. 예를 들어 Batch Job이 매주 한번씩 수행된다고 할때, 각각의 수행되는 Batch Job을 Batch Instance라고 한다.Job Execution배치가 실행될때, 각 배치의 실행시, 실제 수행된 Execution을 정의한다. 예를 들어 Batch Job이 월요일 오전에 수행되었을때, 첫번째 실패하고, 두번째에 Retry에 의해 성공되었다면, 이 각각은 다른 Job Execution이 되고, 같은 작업을 시도하였기 때문에, 같은 Job Instance가 된다..

초경량 Python 웹서버 bottle을 이용한 MVC 예제 + Cookie

초경량 Python 웹서버 bottleMVC 예제 Controller 파일 구현 /controller.py import bottle mythings = ['apple','orange','banana','peach'] @bottle.route('/') def home_page(): fruit = bottle.request.get_cookie("fruit") return bottle.template("hello_world",username="Andrew",things=mythings,like=fruit) @bottle.post('/favorite_fruits') def favorite_fruits(): fruit = bottle.request.forms.get('fruit') if(fruit == None ..