1. 프로젝트 아래 APP만들기
→ 이전에 우리는 FIRST라는 프로젝트를 생성했는데 이제 그 아래 board라는 어플리케이션을 만듭니다. 해당 어플리케이션이 정상적으로 생셩이 되었다면 아래와 같은 구조의 디렉토리와 파일들이 자동적으로 생성될 것입니다.
FIRST:
board __init__.py __init__.pyc manage.py settings.py settings.pyc urls.py
FIRST/board:
__init__.py models.py tests.py views.py
→ 이제 우리는 위의 파일들 중 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를 간단히 설명하면
위의 주소를 아래과 같이 바꾸어봅니다.
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'^$'이라는 부분은 주소를 나타내는 마지막 / 뒤에 아무것도 붙지 않으면 즉 '/' 입력을 나타내는 것입니다.
3. /board/views.py 편집
# Create your views here. from django.http import HttpResponse def index(request): return HttpResponse('HELLO')
위의 라인에 대해서 설명을 드리면 request를 입력으로 받는 index메소드는 HttpResponse('HELLO')를 리턴한다 입니다.
4. 결과
위의 결과가 나온다면 정상입니다 .오늘은 여기까지 집에 가야지. ㅎㅎㅎ
'DJANGO' 카테고리의 다른 글
[DJANGO ADMIN 페이지에서 한글 오류 발생시] (0) | 2013.06.24 |
---|---|
DJANGO #6. Template 적용하기 (0) | 2013.05.17 |
DJANGO #4. Django 프로젝트 생명 및 웹실행 (0) | 2013.04.05 |
DJANGO #3. Python, Django 설치 (0) | 2013.04.03 |
DJANGO #2. Tutorial 설명 (0) | 2013.04.03 |