๋ฐ˜์‘ํ˜•

#ubuntu์—์„œ django


---------------------------------------------------------------------------------

# ์ฐธ๊ณ  

https://tutorial.djangogirls.org/ko/installation/

http://incoffee.tistory.com/6 ---> ์ด๊ฑฐ ๋ณด๊ณ  ํ•จ  

https://uwsgi-docs.readthedocs.io/en/latest/WSGIquickstart.html

http://pythonstudy.xyz/python/article/303-Django-%EC%84%A4%EC%B9%98

https://docs.djangoproject.com/ko/2.0/intro/tutorial01/


# ๋ฒ„์ถ”์–ผ ํ™˜๊ฒฝ ์„ค์ • ๊ด€๋ จ

https://beomi.github.io/2016/12/28/HowToSetup-Virtualenv-VirtualenvWrapper/

---------------------------------------------------------------------------------


[0] apt-get ํŒจํ‚ค์ง€ ์—…๋ฐ์ดํŠธ

$ sudo apt-get update && apt-get upgrade -y


[1] python-pip, python-dev ์„ค์น˜

$ sudo apt-get install python-pip python-dev
$ sudo apt-get install python3-pip python3-dev


[2] ํ™•์ธ

$ pip -V
$ pip3 -V


[3] pip์œผ๋กœ virtualenv virtualenvwrapper ์„ค์น˜

$ pip install virtualenv virtualenvwrapper

$ pip3 install virtualenv virtualenvwrapper


[4] virtualenv ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ

$ virtualenv --python=ํŒŒ์ด์ฌ๋ฒ„์ „ ๊ฐ€์ƒํ™˜๊ฒฝ์ด๋ฆ„

# ex)

$ virtualenv --python=python3.5 ๊ฐ€์ƒํด๋”

$ virtualenv --python=python2.7 ๊ฐ€์ƒํด๋”


[5] ๊ฐ€์ƒํ™˜๊ฒฝ ์‹คํ–‰

$ cd ๊ฐ€์ƒํด๋”/bin/

$ source activate


[6] ์žฅ๊ณ ์„ค์น˜

- pip์ด ์ตœ์‹  ๋ฒ„์ „์ธ์ง€ ํ™•์ธ

$ pip install --upgrade pip

$ pip install django~=1.11.0


[7] ์žฅ๊ณ  ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ

$ cd ๊ฐ€์ƒํด๋”

$ django-admin startproject mysite .


[8] ์žฅ๊ณ  ํ”„๋กœ์ ํŠธ ํ™˜๊ฒฝ์„ค์ • ๋ณ€๊ฒฝ

mysite/settings.py


TIME_ZONE = 'Asia/Seoul'

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

ALLOWED_HOSTS = ['127.0.0.1', '.pythonanywhere.com']


์ถ”๊ฐ€ ๋ฐ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์…‹ํŒ… >> ์ด๋ฏธ ๋‚ด๋ถ€์— sqlite3์ด ์„ค์น˜๋˜์–ด ์žˆ๋‹ค๊ณ  ํ•จ.

DATABASES = {

    'default': {

        'ENGINE': 'django.db.backends.sqlite3',

        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),

    }

}


[9] ์‹คํ–‰ (python ์œผ๋กœ ์‹คํ–‰ํ•˜๊ฑฐ๋‚˜ uWSGI ์œผ๋กœ ์‹คํ–‰)

$ python manage.py migrate ---> ์„œ๋ฒ„ ์ž‘๋™ ํ™•์ธ

$ python manage.py runserver ---> ์„œ๋ฒ„์‹คํ–‰

[9-1] uWSGI๋ฅผ virtualenv์— ์„ค์น˜

$ pip install uwsgi

[9-2] uWSGI ์‹คํ–‰

$ uwsgi --socket :8001 --wsgi-file test.py

[9-3] django ํ”„๋กœ์ ํŠธ ์‹คํ–‰

$ python manage.py runserver

$ uwsgi --socket :8001 --module mysite.wsgi --> ์‹คํ–‰ ๋˜์—ˆ์Œ

>> (test) root@mungmange:/var/www/dev/git_project/dev_toy/py/test/mysite # uwsgi --socket :8001 --module mysite.wsgi

$ uwsgi --http :8001 --module mysite.wsgi #uwsgi --socket :8001 --wsgi-file test.py



[10] nginx ์Šคํฌ๋ฆฝํŠธ

-------------------------------------------

upstream django{

    server localhost:8001;

}

server {


    listen       80;

    server_name  localhost;


    charset utf-8;


location ~ /d {

    uwsgi_pass  django;

include     uwsgi_params; # the uwsgi_params file you installed

}

}

-------------------------------------------

$ service nginx restart


[11] ์ฐธ๊ณ ๋กœ setting.py ํŒŒ์ผ ์ˆ˜์ • ํ›„

$ python manage.py migrate ํ•ด์ฃผ๊ธฐ



[12] ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ

$ python manage.py ๊ฐ€์ƒํด๋” blog



----------------------------------------------------------------------------------------------------------------

# python ์ฟผ๋ฆฌ์…‹


[1] shell ์‹คํ–‰

(test) root@mungmange:/var/www/dev/git_project/dev_toy/py/test/mysite# python manage.py shell



[2] ๊ฐ์ฒด ์กฐํšŒ

>>> from blog.models import Post

>>> Post.objects.all()

<QuerySet [<Post: aa>, <Post: aa>, <Post: aa>, <Post: ad>, <Post: sdf>]>


๋ฐ˜์‘ํ˜•

+ Recent posts