ALTER TABLE django_admin_log CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;

1. 디렉토리 구조 만들기

├── BOARD
│   ├── BOARD
│   │   ├── __init__.py
│   │   ├── __init__.pyc
│   │   ├── settings.py
│   │   ├── settings.pyc
│   │   ├── urls.py
│   │   ├── urls.pyc
│   │   ├── wsgi.py
│   │   └── wsgi.pyc
│   ├── WEB
│   │   ├── css
│   │   ├── html
│   │   ├── img
│   │   ├── js
│   │   └── less
│   ├── WEB.tar.gz
│   ├── board
│   │   ├── __init__.py
│   │   ├── __init__.pyc
│   │   ├── models.py
│   │   ├── tests.py
│   │   ├── views.py
│   │   └── views.pyc
│   └── manage.py
└── django-admin.py

 [Project Name]/WEB/css : css 파일 모음

 [Project Name]/WEB/js   : js 파일 모음

 [Project Name]/WEB/img : 이미지 파일 모음

 -> 해당 파일들은 첨부 파일의 WEB.tar.gz 파일로 첨부했습니다. Project 폴더에서 tar -xvzf WEB.tar.gz 를 입력하시면 됩니다.

      해당 폴더 안에는 Twitter의 WEB UI Framework인 bootstrap가 들어 있습니다.


2. settings.py 설정

STATIC_ROOT = '/home/nijin39/DEV/BOARD/WEB'
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
('css', '/home/nijin39/DEV/BOARD/WEB/css'),
('js', '/home/nijin39/DEV/BOARD/WEB/js'),
('img', '/home/nijin39/DEV/BOARD/WEB/img'),
)

TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
'/home/nijin39/DEV/BOARD/WEB/html'
)

3. HTML 파일 만들기

    <!DOCTYPE html>
    <html>
    <head>
    <title>Bootstrap 101 Template</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- Bootstrap -->
    <link href="/static/css/bootstrap.min.css" rel="stylesheet" media="screen">
    </head>
    <body>
    <h1>Hello, world!</h1>
    <script src="http://code.jquery.com/jquery.js"></script>
    <script src="/static/js/bootstrap.min.js"></script>
    </body>
    </html>

5. 결과



WEB.tar.gz


1. 프로젝트 아래 APP만들기

root@ubuntu:~/django/FIRST# python manage.py startapp board

→ 이전에 우리는 FIRST라는 프로젝트를 생성했는데 이제 그 아래 board라는 어플리케이션을 만듭니다. 해당 어플리케이션이 정상적으로 생셩이 되었다면 아래와 같은 구조의 디렉토리와 파일들이 자동적으로 생성될 것입니다.

root@ubuntu:~/django# ls -R FIRST
FIRST:
board  __init__.py  __init__.pyc  manage.py  settings.py  settings.pyc  urls.py

FIRST/board:
__init__.py  models.py  tests.py  views.py

root@ubuntu:~/django#

→ 이제 우리는 위의 파일들 중 FIRST/urls.py, FIRST/board/views.py를 이용하여 주소가 있는 페이지를 만들어 볼것입니다.

 

2. urls.py 편집

from django.conf.urls.defaults import patterns, include, url

# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'FIRST.views.home', name='home'),
    # url(r'^FIRST/', include('FIRST.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    # url(r'^admin/', include(admin.site.urls)),
)

처음 기본적으로 Django를 설치하면 위의 파일은 지금 보는 것처럼 설정되어 있습니다. urls.py를 간단히 설명하면

우리가 입력하는 주소를 누가 처리할지를 정해주는 곳이라고 보면됩니다. (JAVA의 DISPATCHER라고나 할까요?)

 

위의 주소를 아래과 같이 바꾸어봅니다.

from django.conf.urls.defaults import patterns, include, url

# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'FIRST.views.home', name='home'),
    # url(r'^FIRST/', include('FIRST.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    # url(r'^admin/', include(admin.site.urls)),
    url(r'^$', 'board.views.index'),
)

위의 라인에 대해 설명을 드리자면 설명을 드리지 않겠습니다. 17라인에 대해 설명을 드리면 r'^$'이라는 부분은 주소를 나타내는 마지막 / 뒤에 아무것도 붙지 않으면 즉 '/' 입력을 나타내는 것입니다. 

만약 주소로 0.0.0.0/ 을 입력한다면 이전에 우리가 만들었던 board/views.py의 index 메소드에서 처리한 결과를 출력한다 

 

3. /board/views.py 편집

# Create your views here.

from django.http import HttpResponse

def index(request):
        return HttpResponse('HELLO')

위의 라인에 대해서 설명을 드리면 request를 입력으로 받는 index메소드는 HttpResponse('HELLO')를 리턴한다 입니다.

나를 부르면 나는 웹에다가 HELLO를 찍겠다.

 

4. 결과

 위의 결과가 나온다면 정상입니다 .오늘은 여기까지 집에 가야지. ㅎㅎㅎ

1. 프로젝트 생성

cd /root
mkdir django
cd django
cp /usr/lib/python2.7/dist-packages/django/bin/django-admin.py .
python django-admin.py startproject FIRST

 → 위의 명령어을 정상적으로 수행했다면 아래와 같은 구조의 디렉토리가 생셩되게 됩니다.

root@ubuntu:~/django# ls -R FIRST
FIRST:
__init__.py  __init__.pyc  manage.py  settings.py  settings.pyc  urls.py  urls.pyc

 

2. DB생성

root@ubuntu:~/django# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.5.29-0ubuntu0.12.04.2 (Ubuntu)

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database board;

 

3. DB 및 환경설정

root@ubuntu:~/django/FIRST# vi settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',         # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'board',                                        # Or path to database file if using sqlite3.
        'USER': 'root',                                           # Not used with sqlite3.
        'PASSWORD': '설정하고싶은 비밀번호',      # Not used with sqlite3.
        'HOST': 'localhost',                                   # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '3306',                                          # Set to empty string for default. Not used with sqlite3.
    }
}

TIME_ZONE = 'Asia/Seoul'

→ 위와 같이 DB정보와 함께 TIME_ZONE을 설정하도록 합니다.

 

4. DB 동기화

root@ubuntu02:~/django/FIRST# python manage.py syncdb
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table auth_message
Creating table django_content_type
Creating table django_session
Creating table django_site

 

5. 서비스 시작

root@ubuntu:~/django/FIRST# python manage.py runserver 0.0.0.0:80
Validating models...

0 errors found
Django version 1.3.1, using settings 'board.settings'
Development server is running at http://0.0.0.0:80/
Quit the server with CONTROL-C.

 

6. 서비스 확인

위의 사진이 보인다면 정상적으로 세팅이 된것입니다. 안되었다면 연락주세요..

'DJANGO' 카테고리의 다른 글

DJANGO #6. Template 적용하기  (0) 2013.05.17
DJANGO #5. 어플생성 및 기본 작동 방법 설명  (0) 2013.04.05
DJANGO #3. Python, Django 설치  (0) 2013.04.03
DJANGO #2. Tutorial 설명  (0) 2013.04.03
DJANGO #1. Django 정의 및 특징  (0) 2013.04.03

1. Tutorial OS

우분투 12.04 Desktop 버젼 : 해당 버젼의 설치 가이드는 추후 제공할 예정입니다.

2. Python 설치

해당 버젼에는 Python 2.7 버젼이 기본 설치되어 있습니다.

Python 설치를 확인하는 방법은

root@ubuntu01:/# python -V(대문자)

Python 2.7.3

위와 같이 표시가 되면 정상적으로 설치된 것이라고 볼수 있습니다.

2. Django 설치

3. Mysql 설치

4. MySQLDB 설치

5. easy_install 설치


일단 이것은 나중에 쓰겠습니다. 여기까지는 인터넷에 많습니다. 이 다음이 없어서

조금 순서에 맞지는 않지만 다음 장 먼저 쓰고 이번 장을 쓰도록 하겠습니다. 


1. Tutorial의 목적

    • 프로그램의 'ㅍ'자도 모르는 사람도 해당 예제를 따라하며 기본적인 게시판을 제작하며 프로그래밍 경험을 하게 함.

2. Tutorial이 사용하는 것들
    • Python (추후 파이썬에 대한 강좌도 진행할 예정)
    • Django 
    • Mysql(환경에 따라 sqllite3도 가능)
    • Mysql Workbench
    • 기본적인 Jquery 및 CSS


3. Tutorial 결과 기능들

    • 기본적인 Admin 페이지 작성 및 Login/Logout 기능
    • Form을 이용한 회원 가입 기능
    • 게시판 작성/삭제/변경 기능 
    • Jquery를 이용한 Theme 적용 기능


4. Tutorial 학습 기간

    • 만들때는 시간이 오래 걸리겠지만 학습에는 총 일주일이 넘지 안도록 구성 예정


'DJANGO' 카테고리의 다른 글

DJANGO #4. Django 프로젝트 생명 및 웹실행  (0) 2013.04.05
DJANGO #3. Python, Django 설치  (0) 2013.04.03
DJANGO #1. Django 정의 및 특징  (0) 2013.04.03
Tutorial Guide 만들어보자  (0) 2013.04.02
[DJANGO] 템플릿 활용 예제  (0) 2012.11.14

1. 장고(DJango)가 무엇인가?

"Django is a high-level Python Web Framework that encourages rapid development and clean, pragmatic design."  - http://djangoproject.org

2003년 언론사(Lawrence Journal-World)의 프로젝트 수행 중 만들어낸 내부 프로젝트로 제작자가 가장 좋아하는 기타리스트 Django Reinhardt의 이름을 따서 만든 Python 기반의 Web Framework이다.


2. 장고(DJango)가 지원하는 기능

- ORM(Object-relational mapping) 기능 지원

-  관리자(admin) 페이지의 자동 생성

- 쉬운 URL 파싱 기능 지원

- Template System을 이용하여 쉽게 Dynamic Web Page 작성 가능

- Caching 기능을 이용한 성능 향상 

- il18n을 이용한 다국어 지원


3. 장고(DJango)의 구조

 최근 다른 WebFrame와 마찬가지로 Django도 MVC 패턴을 지원하여 기본 프로젝트 및 파일시스템의 구조 자체가 MVC로 생성되어 짐.

 타 프레임워크에서는 M(Model), V(View), C(Control) 이라고 지칭하나 Django에서는 M(Model), T(Templates), V(Views)라고 지칭하여 각 역할은 아래와 같습니다.

MODEL : DB

VIEWS : Bussiness 로직을 처리

Templates : 처리된 결과를 Web으로 표현

                                

'DJANGO' 카테고리의 다른 글

DJANGO #3. Python, Django 설치  (0) 2013.04.03
DJANGO #2. Tutorial 설명  (0) 2013.04.03
Tutorial Guide 만들어보자  (0) 2013.04.02
[DJANGO] 템플릿 활용 예제  (0) 2012.11.14
기존의 DB와 Django를 연동  (0) 2012.11.02

DJANGO로 APPLICATINO 만들기


  1. DJANGO 특징
  2. 튜토리얼 개요 
  3. DJANGO 환경구축
    1. Python 설치
    2. Django 설치
    3. Mysql 설치
  4. DJANGO 환경 세팅
    1. MYSQL DB 연동
  5. 기본 Tutorial
    1. Template 연동
    2. TEMPLATE 디렉토리 연동
    3. CSS 연동
    4. URL 설정
    5. 기본 HTML 출력
    6. CSS 연동
    7. Extension 연동
  6. DB 연동
    1. DB 입력된 값 출력하기
    2. DB에 특정값 INSERT 하기
    3. DB에 특정값 UPDATE하기
    4. DB의 최종값 출력하기
  7. 게시판 만들기
    1. 게시판 읽기
    2. 게시판 쓰기
    3. 게시판 고치기
  8. 부록 MYSQL WORKBENCH를 이용한 DB설계 및 적용


'DJANGO' 카테고리의 다른 글

DJANGO #3. Python, Django 설치  (0) 2013.04.03
DJANGO #2. Tutorial 설명  (0) 2013.04.03
DJANGO #1. Django 정의 및 특징  (0) 2013.04.03
[DJANGO] 템플릿 활용 예제  (0) 2012.11.14
기존의 DB와 Django를 연동  (0) 2012.11.02

from django.template import Context, loader
from django.shortcuts import render_to_response
from django.http import HttpResponse

def index(request):
    result=[1,2,3]
    t=loader.get_template('template/index.html')
    c=Context({
                'result' : result,
              })
    return HttpResponse(t.render(c))

'DJANGO' 카테고리의 다른 글

DJANGO #3. Python, Django 설치  (0) 2013.04.03
DJANGO #2. Tutorial 설명  (0) 2013.04.03
DJANGO #1. Django 정의 및 특징  (0) 2013.04.03
Tutorial Guide 만들어보자  (0) 2013.04.02
기존의 DB와 Django를 연동  (0) 2012.11.02
python manage.py inspectdb > models.py

 

'DJANGO' 카테고리의 다른 글

DJANGO #3. Python, Django 설치  (0) 2013.04.03
DJANGO #2. Tutorial 설명  (0) 2013.04.03
DJANGO #1. Django 정의 및 특징  (0) 2013.04.03
Tutorial Guide 만들어보자  (0) 2013.04.02
[DJANGO] 템플릿 활용 예제  (0) 2012.11.14

+ Recent posts