Django 공식사이트나 Django Book 사이트에도 잘 정리되어 있지만,
다시한번 처음부터 설치/설정 하는 법을 정리해보았다.
다시한번 처음부터 설치/설정 하는 법을 정리해보았다.
- Django 설치
# apt-get install python-django
- Apache + mod_python 설치
# apt-get install libapache2-mod-python
- 프로젝트 생성
$ mkdir -p /opt/project/web
$ cd /opt/project/web
$ django-admin startproject 프로젝트이름 - 템플릿 디렉토리 설정
$ cd 프로젝트이름
$ mkdir templates
settings.py :
TEMPLATE_DIRS = (
os.path.join(os.path.dirname(__file__), 'templates'),
) - 어플리케이션 생성
$ cd /opt/project/web/프로젝트이름
$ python manage.py startapp 어플리케이션이름 - URL 설정 (urls.py)
from 프로젝트이름.어플리케이션이름.views import *
urlpatterns = patterns('',
(r'^$', index),
) - View 작성
$ cd /opt/project/web/프로젝트이름/어플리케이션이름
$ vi views.py
from django.shortcuts import render_to_response
from django.template import RequestContext
def index(request):
return render_to_response(
'index.html',
) - 템플릿 작성
$ cd /opt/project/web/프로젝트이름/templates
$ vi index.html
<html>
<head><title>The First Page</title></head>
<body><h1>The First Page : Success ^^</h1></body>
</html> - Apache 설정
# cd /etc/apache2/sites-available
# vi 프로젝트이름
NameVirtualHost 아이피:80
<Virtualhost 아이피:80>
ServerName 도메인주소
DocumentRoot /opt/project/web
<Location>
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE 프로젝트이름.settings
PythonDebug On
PythonPath "['/opt/project/web'] + sys.path"
</Location>
<Location "/css">
SetHandler None
</Location>
</Virtualhost>
# a2ensite 프로젝트이름 - 이제, 아파치를 재시작하고 웹브라우즈에서 http://도메인주소/를 입력해보자.




최근 덧글