Beautiful Life...

gauryan.egloos.com


바깥링크

구글


Debian Squeeze 에서 Apache + Django 연동 설치하기 ⊙ 정보통신이야기

Django 공식사이트나 Django Book 사이트에도 잘 정리되어 있지만,
다시한번 처음부터 설치/설정 하는 법을 정리해보았다.

  1. Django 설치
    # apt-get install python-django
  2. Apache + mod_python 설치
    # apt-get install libapache2-mod-python
  3. 프로젝트 생성
    $ mkdir -p /opt/project/web
    $ cd /opt/project/web
    $ django-admin startproject 프로젝트이름
  4. 템플릿 디렉토리 설정
    $ cd 프로젝트이름
    $ mkdir templates

    settings.py :
    TEMPLATE_DIRS = (
    os.path.join(os.path.dirname(__file__), 'templates'),
    )
  5. 어플리케이션 생성
    $ cd /opt/project/web/프로젝트이름
    $ python manage.py startapp 어플리케이션이름
  6. URL 설정 (urls.py)
    from 프로젝트이름.어플리케이션이름.views import *
    urlpatterns = patterns('',
    (r'^$', index),
    )
  7. 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',
    )
  8. 템플릿 작성
    $ 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>
  9. 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 프로젝트이름
  10. 이제, 아파치를 재시작하고 웹브라우즈에서 http://도메인주소/를 입력해보자.


트랙백

이 글과 관련된 글 쓰기 (트랙백 보내기)
TrackbackURL : http://gauryan.egloos.com/tb/2384513 [도움말]

덧글

덧글 입력 영역