페이지

2016년 3월 2일 수요일

django 파일 다운로드

이미지 파일을 다운로드 하여 보여주는 코드 예

views.py
from django.http import HttpResponse
from django.http import FileResponse
import os
import pandas
import matplotlib.pyplot as plt
import numpy as np
from pandas import DataFrame, Series
import StringIO

def index(request):
    return HttpResponse("dir : %s <br><img src='image1'>" % (os.getcwd()))
def image1(request):
    response = FileResponse(open('image.png', 'rb'), content_type='image/png')
    return response


참고링크
https://docs.djangoproject.com/en/1.9/ref/request-response/#django.http.HttpResponse

HttpResponse 를 이용한 구현 예

def image2(request):
    response = HttpResponse(open('image.png', 'rb'), content_type='image/png')
    response['Content-Disposition'] = 'attachment; filename="image2.png"'
    return response

Pandas Series 차트 이미지를 다운로드 하는 예

import pandas
import matplotlib.pyplot as plt
import numpy as np
from pandas import DataFrame, Series
import StringIO
def chart1(request):
    s1 = Series([1,3,2,4,5])
    s1.plot(title="g")
    bufferIO = StringIO.StringIO()
    plt.savefig(bufferIO)
    bufferIO.seek(0)
    response = HttpResponse(bufferIO, content_type='image/png')
    response['Content-Disposition'] = 'attachment; filename="chart.png"'
    return response

2016년 2월 5일 금요일

python anaconda 및 각종 라이브러리 설치


Anaconda
https://www.continuum.io/

conda install ipython 

conda install jupyter

jupyter notebook


conda install django

conda install Flask
http://flask.pocoo.org/

conda install pymysql
https://github.com/PyMySQL/PyMySQL

2015년 9월 7일 월요일

라즈베리파이 파일전송 방법

라즈베리파이로 파일을 전송하기위한 방법입니다.


  1. lxterminal 을 열고 ifconfig 를 실행하여 ip 주소를 확인합니다.
  2. 게스트 컴에서 FileZilla 를 실행하고 사이트 관리자를 열어줍니다.
  3. 새 사이트를 만들고 프로토콜을 SFTP 로 설정합니다.
  4. 사용자명에 pi 비밀번호에 raspberry 를 입력하고 연결합니다.

라즈베리파이에서 시작프로그램 등록 방법

부팅시 Rasbian LXDE Desktop 에서 python 스크립트가 자동으로 실행되도록 하는 방법입니다.

  • /etc/xdg/lxsession/LXDE-pi/autostart 에 아래 내용을 추가합니다.
@/usr/bin/python /home/pi/example.py

참고사이트