본문 바로가기

django

Django 를 이용하여 Google App Engine을 이용하는 경우 template과 static(css, img...) 파일 사용법 1. template 사용법settings 파일을 수정한다. import os.path PROJECT_DIR = os.path.dirname(__file__) 라고 PROJECT_DIR을 설정한 이후TEMPLATE_DIRS 에 템플릿 디렉토리를 입력한다.예 ) TEMPLATE_DIRS = ( #templates 디렉토리가 setting 디렉토리와 같은 위치에 위치하는경우 os.path.join(PROJECT_DIR, 'templates'), ) 2. static사용법app.yaml 파일을 수정한다.최 상위 디렉토리 (src 디렉토리) 에 static 이라는 디렉토리 생성 후 - url: /static static_dir: static 위와 같이 입력한다. 사용법은 /static/style.css 그냥 이.. 더보기
Django(1.4 이상)를 이용하여 Google App Engine 개발하기 (Eclipse 사용) Python : 2.7Django : 1.4 Python 개발 Eclipse plugin "PyDev"는 이미 깔려있다.Google App Engine 이 Django 1.4 까지 지원하는것 같다.Django 가장 최근버전이 1.5 이지만 1.4를 깐다.Google App Engine SDK도 잘 구해서 깐다. 1. Django 프로젝트(django_gae)를 생성한다. 2. PyDev Package Explorer 가 아닌 Navigator로 확인해보면 설정파일인 .pydevproject 파일이 보인다..pydevproject 파일이 보이지 않는다. Window > Show View > Other > Navigator 를 선택하여 Navigator로 확인하자 딱 보인다. 파일을 열어 보면.pydevpr.. 더보기
Django tutorial part4. (Form 작성) 1. polls/template/polls/detail.html 에 Form을 작성해보자 {{ poll.question }} {% if error_message %}{{ error_message }}{% endif %} {% csrf_token %} {% for choice in poll.choice_set.all %} {{ choice.choice_text }} {% endfor %} 2. polls/views.py 의 vote 함수를 수정해보자 def vote(request, poll_id): p = get_object_or_404(Poll, pk = poll_id) try: selected_choice = p.choice_set.get(pk=request.POST['choice']) except (.. 더보기
Django tutorial part3. 2/2 (화면 만들기) 1. 에러 처리 polls/templates/polls/detail.html 파일을 작성한다. {{ poll.question }} {% for choice in poll.choice_set.all %} {{ choice.choice_text }} {% endfor %} polls/views.py 파일의 detail 함수를 아래와 같이 수정한다. from django.http import Http404 def detail(request, poll_id): try: poll = Poll.objects.get(pk = poll_id) except Poll.DoesNotExist: raise Http404 return render(request, 'polls/detail.html', {'poll':poll}) .. 더보기
Django tutorial part3. 1/2 (화면 만들기) 1. polls/views.py 파일을 아래와 같이 작성한다. from django.http import HttpResponse def index(request): return HttpResponse("Hello. world. You're at the poll index.") 2. polls/urls.py 파일을 생성하고 아래와 같이 작성한다. from django.conf.urls import patterns, url from polls import views urlpatterns = patterns('', url(r'^$', views.index, name = 'index') ) 3. mysite/url.py 파일을 아래와같이 수정한다. from django.conf.urls import patter.. 더보기
Django tutorial part2. (관리자 화면 활성화) 원문 : https://docs.djangoproject.com/en/1.5/intro/tutorial02/ admin 사이트를 활성화 시키자. 1. mysite/settings.py 파일의 INSTALLED_APPS 를 수정한다.'django.contrib.admin', : 주석해제 한다. INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', # Uncomment the next line to enable the admin: 'djang.. 더보기
Django Tutorial part1. (프로젝트 생성, Model 정의) 원문 : https://docs.djangoproject.com/en/1.5/intro/tutorial01/ 0. 장고(Django)를 깐다 (https://docs.djangoproject.com/en/1.5/topics/install/)(이클립스에 PyDev 플러그인이 깔려있다고 가정한다.) 1. mysite 라는 이름으로 Django 프로젝트를 생성한다. 2. 아래 사진과 같은 파일들이 생성된다.- manage.py : Django 프로젝트를 관리하기 위한 utility. 자세한 내용은 (https://docs.djangoproject.com/en/1.5/ref/django-admin/)- mysite/settings.py : Django 프로젝트와 관련된 세팅 정보- mysite/urls.py :.. 더보기