336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

python /var/www/example.com/src/example/manage.py startapp app


sudo vim /var/www/example.com/src/example/example/setting.py

INSTALLED_APPS = [
    'django.contrib.admin',
    '.........
    'app',
]


sudo vim /var/www/example.com/src/example/example/urls.py

from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'', include('app.urls', namespace="app")),
]


cd /var/www/example.com/src/example/app/

sudo vim urls.py

from django.conf.urls import patterns, url
from app import views

urlpatterns = [
    url(r'^$', views.index, name='index'),
]


cd /var/www/example.com/src/example/app/

sudo vim views.py

from django.shortcuts import render
#from django.http import HttpResponse
def index(request):
  #return HttpResponse("home")
  return render(request, 'app/index.html', {})


mkdir /var/www/example.com/src/example/app/templates/app

sudo vim /var/www/example.com/src/example/app/templates/app/index.html

"hello"


cd /var/www/example.com/src/example/
sudo python manage.py createsuperuser


'Web Service > Django' 카테고리의 다른 글

django 버전 확인  (0) 2016.03.09
우분투에서 nginx + uwsgi + django 연동  (0) 2016.03.08
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

python2.x

$python -c "import django; print(django.get_version())"


python3.x

$python3 -c "import django; print(django.get_version())"

'Web Service > Django' 카테고리의 다른 글

django application 만들기  (0) 2016.03.09
우분투에서 nginx + uwsgi + django 연동  (0) 2016.03.08
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

sudo adduser user
sudo adduser user sudo
su user


sudo echo "localhost" > /etc/hostname
sudo hostname localhostsudo apt-get update
sudo apt-get upgrade


sudo apt-get install python
sudo apt-get install python-virtualenv
sudo apt-get install python2.7-dev


sudo apt-get install nginx
sudo service nginx start


sudo apt-get install uwsgi


sudo mkdir /var/www
sudo mkdir /var/www/example.com
cd /var/www/example.com
sudo mkdir venv conf src logs


sudo virtualenv /var/www/example.com/venv
source /var/www/example.com/venv/bin/activate (해제는 deactivate)
(venv)$ sudo pip install django


cd /var/www/example.com/src
(venv)$ django-admin.py startproject example


sudo vim /var/www/example.com/conf/uwsgi.ini (신규생성)

[uwsgi]
# variables
projectname = example_project
projectdomain = example.com
base = /var/www/example.com
# config
plugins = python
master = true
protocol = uwsgi
env = DJANGO_SETTINGS_MODULE=%(projectname).settings
pythonpath = %(base)/src/%(projectname)
module = %(projectname).wsgi
socket = 127.0.0.1:8889
logto = %(base)/logs/uwsgi.log
#below line runs it as a daemon in background
daemonize = /var/log/uwsgi/example_project.log


sudo vim /var/www/example.com/conf/nginx.conf (신규생성)

server {
    listen 80;
    server_name example.com www.example.com;
    root /var/www/example.com/src/example_project;
    access_log /var/www/example.com/logs/access.log;
    error_log /var/www/example.com/logs/error.log;

    location /static/ { # STATIC_URL
        alias /var/www/example.com/src/static/; # STATIC_ROOT
        expires 30d;
    }

    location /media/ { # MEDIA_URL
        alias /var/www/example.com/src/media/; # MEDIA_ROOT
        expires 30d;
    }

    location / {
        include uwsgi_params;
        uwsgi_pass 127.0.0.1:8889;
    }
}


sudo vim /etc/nginx/nginx.conf (기존파일 수정)

user    www-data;
# ...
http {
    # ...
    include /var/www/*/conf/nginx.conf;
    # ...
}


sudo service nginx restart


# mysql 사용시
# sudo apt-get install mysql-server
# sudo mysql_secure_installation
# sudo apt-get install python-mysqldb


sudo apt-get install uwsgi-plugin-python


sudo pip install south (optional)


sudo uwsgi --ini /var/www/example.com/conf/uwsgi.ini


sudo vim settings.py (기존파일 수정)

DEBUG = False
ALLOWED_HOSTS = '*'


sudo vim /etc/init/uwsgi.conf (신규생성)

# Emperor uWSGI script
description "uWSGI Emperor"
start on runlevel [2345]
stop on runlevel [06]
exec uwsgi --master --die-on-term --emperor /var/www/example.com/conf/uwsgi.ini


sudo reboot


# 참고 사이트
# http://tutorial.djangogirls.org/ko/django_urls/index.html
# http://blog.richard.do/index.php/2013/04/setting-up-nginx-django-uwsgi-a-tutorial-that-actually-works/
# http://blog.collabspot.com/2012/08/14/setting-up-nginx-uwsgi-python-ubuntu-12-04/
# http://abipictures.tistory.com/918

'Web Service > Django' 카테고리의 다른 글

django application 만들기  (0) 2016.03.09
django 버전 확인  (0) 2016.03.09

+ Recent posts