템플릿 재사용 : 일반 레이아웃을위한 기본 템플릿을 만들고 개별 페이지에 대한 세부 템플릿을 사용해야합니다. 이 내용은 이미 Django documentation에 자세히 설명되어 있습니다.
from django.shortcuts import render_to_response as django_render_to_response
def render_to_response(template, params, context_instance):
return django_render_to_response(template,
AppendStandardParams(request, params),
context_instance)
: 그 일반적인 부품에하는 경향이 무엇
(예를 들어 말의 사용에있는 사이트의 현재 부분을 강조 메뉴), 내 자신의 render_to_response
기능을 만들려면 다음에 가깝다 이 예에서
def AppendStandardParams(request, params):
if request.META['PATH_INFO'].startswith('/customer'):
params['category'] = 'customer'
params['title'] = 'Customer overview'
# and so on for all different parts
이 category
및 title
태그 메뉴를 강조하기 위해 사용되는 일부 값이 구성됩니다
는 ApplyStandardParams
방법은 현재 경로에 따라 메뉴를 구성 제목 등. 예를 들어 :
<!-- Customer menu entry: change class if this is the current category. -->
<li{% if category == "customer" %} class="selected"{% endif %}>Customers</li>
마지막으로, 대신 일반
render_to_response
수입의, 뷰에서 사용하는, 난 그냥보기에 내 사용자 정의 버전을 사용할 수 있습니다
from lib.views import *
같은 것을 수행. 이 방법으로 뷰의 모든 코드 구문이 동일하게 유지되지만 새 뷰나 앱을 만들 때마다 메뉴를 사용자 정의 할 필요가 없습니다.
출처
2011-10-26 06:43:24
jro
그 트릭을해야합니다 :) 탱크 당신 –