def list_ajax(reqest):
#q = request.GET.get('q',None)
#get all where var = q.
return ...
list_ajax = condition(etag_func=list_ajax)(list_ajax)
ご覧のとおり、結果が同じ場合は、304をクライアントに返そうとしています。しかし、私はこのDjangoエラーを受け取っています、なぜですか?:
Traceback:
File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py" in get_response
92. response = callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/views/decorators/http.py" in inner
130. response['ETag'] = quote_etag(res_etag)
File "/usr/local/lib/python2.6/dist-packages/django/utils/http.py" in quote_etag
118. return '"%s"' % etag.replace('\\', '\\\\').replace('"', '\\"')
Exception Type: AttributeError at /list/ajax/
Exception Value: 'HttpResponse' object has no attribute 'replace'
編集:私はこれをしました:
def etag_generate(p):
thestring = cPickle.dumps(p)
return thestring
@etag(etag_generate)
def list_ajax(request):
...
etag_generate(mydictresults)
return render_to_response("list.html",mydictresults)
この辞書からハッシュが生成されることを期待して、すべての結果を文字列に変換しています。しかし、@etagではcPickleを生成できないようです。エラーは次のとおりです。
Exception Type: TypeError at /list/ajax/
Exception Value: can't pickle file objects