0

これはdjangoのドキュメントからのものです:

condition(etag_func=None, last_modified_func=None)
etag(etag_func)
last_modified(last_modified_func)

These decorators can be used to generate ETag and Last-Modified headers

それでも、これもdjangoのドキュメントからのものです:

Additionally, the cache middleware automatically sets a few headers in each HttpResponse:
Sets the Last-Modified header to the current date/time when a fresh (uncached) version of the page is requested.
Sets the Expires header to the current date/time plus the defined CACHE_MIDDLEWARE_SECONDS.
Sets the Cache-Control header to give a max age for the page -- again, from the CACHE_MIDDLEWARE_SECONDS setting.

したがって、サイトごとのキャッシュと条件デコレータの両方を使用する場合、 Last-Modified がどのような値を取るのか疑問に思っていました。
編集:また、両方を使用することをお勧めしますか、それとも一方だけを使用することをお勧めしますか?

4

1 に答える 1

1

キャッシュ ミドルウェアは、ヘッダーとヘッダーがまだ存在しない場合にのみ設定しETagますLast-Modified( ExpiresUpdateCacheMiddleware から呼び出される patch_response_headers メソッドを参照しください) 。

また、ビューから応答が返された直後にデコレーターが実行されるため、ミドルウェアの実行時にデコレーター ヘッダーが既に存在します。

要するに: Last-Modifiedcondition/last_modified デコレータからの値を持ちます。

于 2011-08-15T00:21:39.237 に答える