1월, 2014의 게시물 표시

django 설치 요약본

1. python 설치 ( http://www.python.org/ ) python-2.7.6.msi 2. django 설치 ( https://www.djangoproject.com/download/ ) Django-1.6.tar.gz 파일을 풀어서 c:\Django-1.6 압축 해제, 폴더에서 아래 명령 수행 python setup.py install 환경변수 추가 path=C:\Python27\; C:\Python27\Scripts python 실행 >>> import django >>> django.get_version() 3. SQL 2008 실행 pywin32 (windows 에서 사용하기 위한 확장용) 프로그램 설치 http://sourceforge.net/projects/pywin32/ pywin32-218.win32-py2.7.exe를 다운받으면 된다. https://bitbucket.org/Manfre/django-mssql/overview 사이트에 접속하여 django-mssql 을 다운받는다. Manfre-django-mssql-29c4d4ecc011.zip 파일 압축풀고, 폴더에서 아래 명령 수행 python setup.py install mysite.setting.py 를 아래와 같이 수정 DATABASES = {     # 'default': {     #     'ENGINE': 'django.db.backends.sqlite3',     #     'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),     # }     'default': {         'NAME': 'SITE',         'ENGINE': 'sqlserver_ado',         '

Test & distribute

Running tests In the terminal, we can run our test: $ python manage.py test polls Your project and your reusable app After the previous tutorials, our project should look like this: mysite/ manage.py mysite/ __init__.py settings.py urls.py wsgi.py polls/ __init__.py admin.py models.py static/ polls/ images/ background.gif style.css templates/ polls/ detail.html index.html results.html tests.py urls.py views.py templates/ admin/ base_site.html Installing some prerequisites The current state of Python packaging is a bit muddled with various tools. For this tutorial, we’re going to use  setuptools  to build our package. It’s the recommended packaging tool (merged with the distribute  fork). We’ll also be using  pip  to in

tar, gzip 압축풀기 예제

아래의 코드는 내가 만든 소스는 아니고 인터넷에서 찾아서 실행한 예제이다. 원래의 소스에서 일부는 수정하였고, 테스트를 위해 console 화면을 개발하였다. 소스를 다운받는 경우 gzip으로 압축된 경우가 많아서 tarfile로 gzip을 푸는 프로그램이 있으면 좋을것 같아 만들어 보았다. tar_open : 압축된 파일을 현재 폴더에 푼다. tar_info : 압축된 폴더에 있는 파일의 정보를 읽어 화면에 출력한다. tar_add : tar 파일 형식으로 압축한다.(zip 과 같은 형태임) 알집같은 툴을 사용해서 풀수도 있지만 파이썬이 있으면 unix 용 압축프로그램은 왠만한건 다 풀 수 있는것 같아 별도 툴이 필요 없어보인다. #How to extract an entire tar archive to the current working directory: import tarfile import sys def tar_open(filename): tar = tarfile.open(filename) tar.extractall() tar.close() #How to create an uncompressed tar archive from a list of filenames: def tar_add(targetfilename, *arglist): tar = tarfile.open(targetfilename, "a") for name in arglist:    tar.add(name) tar.close() #How to read a gzip compressed tar archive and display some member information: def tar_info(filename): if tarfile.is_tarfile(filename): tar=tarfile.open(filename) else: tar = tarfile.open(filename, "

pip 설치

http://www.pip-installer.org/en/latest/installing.html pip 설치 메뉴얼 설치메뉴얼이라고 할만한건 없지만 한번씩 잊어버려서 간략하게 적어본다. 링크 사이트에 가면 자세한 설명이 있다. 파이썬 버전은 2.7이나 3.3버전에서 동일하고 pip를 사용하기 위해서는 setuptools가 필요한다. 위 링크 사이트에서 ez_setup.py를 다운받아 python ez_setup.py 라고 입력하면 setuptools-2.0.1.tar 파일이 다운로드 된다. 그리고 알아서 site-package에 setuptools-2.0.1-py3.3 파일이 들어간다. scripts 폴더에 easy_install 로 시작하는 파일들이 생성된다. 링크를 클릭했을때 웹에서 텍스트 파일로 보일 때가 있는데 그런 경우 브라우져에서 전체 선택후 텍스트 파일을 메모장에 붙여 저장하면 된다. 저장 폴더는 python이 설치된 경로에 넣으면 된다. 정상적으로 실행이 되었다면 Install or Upgrade pip 에서 get-pip.py 링크를 클릭해서 다운로드 받는다. 마찬가지로 파일은 python 설치경로에 다운로드 받는다. python get-pip.py 라고 입력을 하면 동일하게 사이트에서 다운로드 받아 설치를 시작한다. 만약 pip를 입력했는데 내부명령어를 못찾는다면 path에 c:\python27\scripts를 추가한다. 간략정리. 1. ez_setup.py ,get-pip.py 파일 다운로드 2. python ez_setup.py 수행 3. python get-pip.py 수행 4. pip라고 입력해 본다. 도움말이 나오면 정상. python 에 라이브러리를 설치하려고 보면 pip 명령을 입력하게 나오는 곳이 많다. pip에 모듈명을 입력하면 해당 사이트에서 설치파일들을 다운로드 받아 알아서 설치를 해준다. 그렇지 않은 경우에는 사이트에 접속해서 zip 파일이나 git에서 다운로드 받아서 p

MS SQL로 DB 연결방법

이미지
MS SQL 2008에 설치하는 방법 http://django-mssql.readthedocs.org/en/latest/index.html 링크의 문서를 확인해보면 MS SQL 서버에서 DB를 구동하기 위해서는 pywin32와 python 2.6 이상을 설치해야 한다. 현재 내가 사용하고 있는 python 버전은 2.7이므로 사용 가능하다. pywin32는 windows 에서 사용하기 위한 확장용 프로그램인것 같다. http://sourceforge.net/projects/pywin32/ 여기를 클릭해서 pywin32를 다운받아서 설치한다. 다운로드 페이지 참고. 현재 버전이 Build218이다. pywin32-218.win32-py2.7.exe를 다운받으면 된다. c:\python27이 설치되어 있으면 해당폴더가 선택되어 있고, 다음을 누르면 설치가 완료된다. https://bitbucket.org/Manfre/django-mssql/overview 사이트에 접속하여 django-mssql 을 다운받는다. 화면에 접속하면 오른쪽 상단에 download 링크가 있다. zip 파일을 받아서 아무 폴더에 압축을 해제한다. python setup.py install 명령을 입력하면 site-package에 설치를 한다. http://django-mssql.readthedocs.org/en/latest/quickstart.html#installation 다시 설치문서를 보자. 설치문서에서 SQL 셋팅하는 방법이 나와 있다. 개발하고 있는 site에 settings.py 파일을 열고 DB 부분을 아래와 같이 수정한다. NAME은 DB명, HOST에는 서버명을 호스트명이나 IP로 입력한다. USER, PASSWORD는 로그인할 아이디 패스워드를 입력한다. 입력하지 않으면 Trusted mode로 접속한다. 한가지 주의할점은 내가 테스트 한 환경에서는 HOST명을 127.0.0.1\\ss2008로 하였