Created
March 29, 2010 08:25
-
-
Save wil/347596 to your computer and use it in GitHub Desktop.
Django Setting Expires Header in XHR Response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from django.utils.http import http_date | |
AJAX_NEGATIVE_CHECK_EXPIRES = 60 # object is still available | |
AJAX_POSITIVE_CHECK_EXPIRES = 60*10 # if object is not available (or taken) | |
def check_ajax(request): | |
# do stuff here | |
timeout = AJAX_NEGATIVE_CHECK_EXPIRES if avail else AJAX_POSITIVE_CHECK_EXPIRES | |
response = HttpResponse(json_result, mimetype='application/json') | |
response['Expires'] = http_date(time.time() + timeout) | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment