TechTogetWorld


 daviduino.co.kr

techtogetworld.com

 david201207.blog.me

cafe.naver.com/3dpservicedavid


기존에 작성했던 투표관련 웹 "vote" Django WEB 을  pythonanywhere에 배포하는 과정입니다.

특히 디렉토리 구조에 신경쓰지 않으면, 배포시 에러가 발생하므로, 유심히 볼 필요가 있습니다.

글의 순서는 아래와 같습니다.


===========================================================================

[ 배포하기]==> PythonAnywhere
1. GIT, GITHUB를 설치하고, 저장소를 만들어서 저장한다
2. GitHub에서 PythonAnywhere로 코드 가져오기
3. PythonAnywhere에서 가상환경(virtualenv) 생성하기
4. PythonAnywhere에서 데이터베이스 생성하기
5. web app으로 블로그 배포하기

6. 가상환경(virtualenv) 설정하기

7. WSGI 파일 설정하기

8. 구현된 모습 : 정상작동중

   ==>http://david20120720.pythonanywhere.com/

9. 참고 : pythonanywhere 가입후 자동설치되는 화일 구조

10. source file

vote.zip




[ 참고자료

     https://programmers.co.kr/learn/courses/6

===========================================================================




[ 배포하기]==> PythonAnywhere

1. GIT, GITHUB를 설치하고, 저장소를 만들어서 저장한다

   ==> 참고글 http://daviduino.co.kr/86

  - github에 올려진 형태 : 디렉토리 구조가 틀리면 web 실행시 에러 발생함, 구조를 맞추어야 함.


2. GitHub에서 PythonAnywhere로 코드 가져오기

  - 배시(Bash)" 콘솔을 실행해서, 콘솔화면으로 들어간다

  - PythonAnywhere command-line

   . $ git clone https://github.com/david20120720/vote.git

   . $ tree vote 명령어를 입력  ==> 화일이 제대로 불러와졌는지 확인가능 , 디렉토리 구조가 틀리면 배포시 에러 발생함

PythonAnywhere command-line

$ tree vote

13:27 ~ $ tree vote 

vote

├── db.sqlite3

├── elections

│   ├── __init__.py

│   ├── __pycache__

│   │   ├── __init__.cpython-36.pyc

│   │   ├── admin.cpython-36.pyc

│   │   ├── models.cpython-36.pyc

│   │   ├── urls.cpython-36.pyc

│   │   └── views.cpython-36.pyc

│   ├── admin.py

│   ├── apps.py

│   ├── migrations

│   │   ├── 0001_initial.py

│   │   ├── 0002_auto_20170910_1447.py

│   │   ├── 0003_auto_20170910_1714.py

│   │   ├── __init__.py

│   │   └── __pycache__

│   │       ├── 0001_initial.cpython-36.pyc

│   │       ├── 0002_auto_20170910_1447.cpython-36.pyc

│   │       ├── 0003_auto_20170910_1714.cpython-36.pyc

│   │       └── __init__.cpython-36.pyc

│   ├── models.py

│   ├── templates

│   │   └── elections

│   │       ├── area.html

│   │       └── index.html

│   ├── tests.py

│   ├── urls.py

│   └── views.py

├── manage.py

└── mysite

    ├── __init__.py

    ├── __pycache__

    │   ├── __init__.cpython-36.pyc

    │   ├── settings.cpython-36.pyc

    │   ├── urls.cpython-36.pyc

    │   └── wsgi.cpython-36.pyc

    ├── settings.py

    ├── urls.py

    └── wsgi.py


3. PythonAnywhere에서 가상환경(virtualenv) 생성하기

  - PythonAnywhere command-line

$ cd vote

$ virtualenv --python=python3.6 myvenv

Running virtualenv with interpreter /usr/bin/python3.6

[...]

Installing setuptools, pip...done.

$ source myvenv/bin/activate

(myvenv) $  pip install django~=1.11.0

Collecting django

[...]

Successfully installed django-1.11.3

5분정도 시간이 소요될수 있음


4. PythonAnywhere에서 데이터베이스 생성하기

 - pythonAnywhere command-line

   . (mvenv) $ python manage.py migrate

Operations to perform:

[...]

     Applying sessions.0001_initial... OK

   . (mvenv) $ python manage.py createsuperuser


5. web app으로 블로그 배포하기

  - PythonAnywhere 대시보드 ==>Web==>Add a new web app

  - 도메인 이름을 확정한 후, 대화창에 수동설정(manual configuration)

  - Python 3.6을 선택하고 다음(Next)을 클릭하면 마법사가 종료됩니다.

    . Note "Django"가 아니라  "수동설정(Manual configuration)"을 선택해야함

    . 기본 PythonAnywhere Django 설정을 위해서 이방법이 유리함.



6. 가상환경(virtualenv) 설정하기

 - "가상환경(Virtualenv)" 섹션에서 가상환경 경로를 입력(Enter the path to a virtualenv) ==> /home/david20120720/vote/myvenv/

    라고 입력

7. WSGI 파일 설정하기

 - "WSGI 설정 파일(WSGI configuration file)" ==> /var/www/<your-username>_pythonanywhere_com_wsgi.py부분) 클릭

 - 모든내용을 삭제==>아래 내용으로 기록

import os

import sys

path = '/home/david20120720/vote/'  # PythonAnywhere 계정으로 바꾸세요. ==> vote까지만 입력한다, mysite 까지 들어가면 에러 발생함.

if path not in sys.path:

    sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

from django.core.wsgi import get_wsgi_application

from django.contrib.staticfiles.handlers import StaticFilesHandler

application = StaticFilesHandler(get_wsgi_application())

8 directories, 32 files


  - 저장=> WEB 클릭

  - 모두 끝았음. RELOAD 및 홈페이지 실행시 웹이 실행됨


8. 구현된 모습 : 정상작동중   



9. 참고 : pythonanywhere 가입후 자동설치되는 화일 구조

    


 10. source file





[ 참고자료]