質問

私はDjangoの要求処理を有効にしている。

TEMPLATE_PROCESSORS = (
"django.core.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.request",
)

まだ私は、テンプレートで使用できる変数を要求する必要はありません。 私は手動でそれを渡すようにしました。ジャンゴ1.0.2を使用して どこでもウェブ上でたった約有効になっているようだリクエストプロセッサ..

また、私はRequestContextのを使用しています

 return render_to_response(
    'profile.html',
    {
        'persons':Person.objects.all(),
        'person':Person.objects.get(id=id),
         'request':request,
    },
    context_instance=RequestContext(request)
)

おおくそ そのための新しい名前があるの TEMPLATE_CONTEXT_PROCESSORS

役に立ちましたか?

解決

settings.pyます:

TEMPLATE_CONTEXT_PROCESSORS = (
  # ...
  'django.core.context_processors.request',
  # ...
)

他のヒント

TEMPLATE_CONTEXT_PROCESSORS の代わりに TEMPLATE_PROCESSORS

ジャンゴ1.8のように、これは「テンプレート」設定に変更されている、とデフォルトの設定では、要求プロセッサが含まれていないことをご承知おきます。

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [
        # insert your TEMPLATE_DIRS here
    ],
    'APP_DIRS': True,
    'OPTIONS': {
        'context_processors': [
            # Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
            # list if you haven't customized them:
            'django.contrib.auth.context_processors.auth',
            'django.template.context_processors.debug',
            'django.template.context_processors.i18n',
            'django.template.context_processors.media',
            'django.template.context_processors.static',
            'django.template.context_processors.tz',
            'django.contrib.messages.context_processors.messages',
        ],
    },
},]

ただ、問題を解決するためにバックで要求処理を追加します:

'django.core.context_processors.request',

詳細情報については、 Djangoはドキュメントをアップグレードを参照してください。

あなたがテンプレートに利用できるrequest変数を持っていませんか?あなたが行を削除するとどうなります

'request':request,

それは、その行が存在する場合とは異なります。あなたのテンプレートが同じいずれかの方法をロードした場合、問題はあなたのテンプレートである。

MIDDLEWARE_CLASSES =( ... 「yourfolder.yourfile.yourclass」 ... YOURCLASSます:

クラスAddRequestToTemplate: process_templaet_response(自己、要求、応答): response.context_data [ '要求'] =要求

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top