두 가지 옵션은 내가 참조 :
1) 다음 상황에 삽입) 플랫 파일에서 (즉,이 임의의 견적을로드하는 상황 프로세서를 사용합니다. 예 :
# create your own context-processor file (myutils/context_processors.py)
def my_random_quote_processor(request):
context = {}
# generate your string you want in template
# ....
context['RANDOM_QUOTE'] = my_random_quote
return context
# in settings.py, tell django to include your processor
TEMPLATE_CONTEXT_PROCESSORS = (
# ...,
'myutils.context_processors.my_random_quote_processor'
)
# in your base template, just include the template var
<p>quote: {{ RANDOM_QUOTE }}</p>
# make sure in your views, you set the context_instance
def my_view(request):
# ...
return render_to_response('myapp/mytemplate.html', c,
context_instance=RequestContext(request))
2) 내가 템플릿 태그에 투표 것이다 당신이 플랫 파일에서 견적을로드 사용자 정의 템플릿 태그 등 : http://docs.djangoproject.com/en/dev/howto/custom-template-tags/
데이터베이스를 통해 플랫 파일을 사용하려는 특별한 이유가 있습니까? – KyleWpppd
슬로건은 거의 변하지 않을 것이며 그 중 일부만 있습니다. db 캐싱을 사용하는 경우에도 모든 페이지 머리글에 문장을 넣기 위해 별도의 응용 프로그램을 만들고 유지 관리하는 불필요한 복잡성 (또는 관련없는 기존 응용 프로그램을 더티하게 처리하는 것)처럼 보입니다. 나에게 논리적 인 장소는 내'header.html' 템플릿에'base.html' 템플릿에 포함되어 있어야합니다. – gorus
내 생각에 무작위로 슬로건을 선택하는 기능이 있다면 데이터베이스는 플랫 파일을 사용하는 것보다 훨씬 효율적으로 처리 할 수 있습니다. db에 대한 호출을 캐시 할 수 있지만 귀하의 슬로건에 대한 호출을 할 수 있습니까? – KyleWpppd