すべてのDjangoの機能がAppEngineで機能するわけではありません。そのため、App Engineインフラストラクチャの制限により、使用しようとしている機能はAppEngineDjangoライブラリに許容されません。
私があなたを正しく理解しているなら、あなたはページ全体、言い換えればビュー全体の応答をキャッシュしたいですか?あなたはそのようにこれを行うことができます(単なる例):
# Django on App Engine view example
from google.appengine.api import memcache
from django.http import HttpResponse
def cached_index_page(request):
output_html = memcache.get('index_page') # here we "take" from cache
if output is not None:
pass
else:
output_html = get_page_content()
memcache.add('index_page', output_html, 60) # here we "put" to cache" (timeout also here)
HttpResponse(output_html)
目的に応じて、必要なページを自動キャッシュするDjangoのミドルウェアを作成できます。
また、AppEngineのものに関係のない/受け入れられないものをすべて構成ファイルから削除したことを確認してください。ヘルプページ( https://developers.google.com/appengine/articles/django )を考慮すると、最小限の設定は次のようになります。
import os
# 'project' refers to the name of the module created with django-admin.py
ROOT_URLCONF = 'project.urls'
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
# 'django.contrib.sessions.middleware.SessionMiddleware',
# 'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.doc.XViewMiddleware',
'google.appengine.ext.ndb.django_middleware.NdbDjangoMiddleware', # NoSQL db middleware
)
INSTALLED_APPS = (
# 'django.contrib.auth',
'django.contrib.contenttypes',
# 'django.contrib.sessions',
'django.contrib.sites',
)
ROOT_PATH = os.path.dirname(__file__)
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.
ROOT_PATH + '/templates',
)
App Engineには独自のネイティブキャッシュがあることを忘れないでください。たとえば、Pythonランタイム環境は単一のウェブサーバー上のリクエスト間でインポートされたモジュールをキャッシュし、インポートされたモジュールに加えて、CGIハンドラスクリプト自体をキャッシュするようにAppEngineに指示できます。
役立つリンク:
https ://developers.google.com/appengine/articles/django-nonrelhttps://developers.google.com/appengine/docs/python/tools/libraries27