Setting request.session causes HTTP 500 Error when posting form to Django -
even setting session simple string changes http response status 200 500. httml button has id="requestquote". webpage javascript:
$('#requestquote').click(function(){ var jpicks = json.stringify(picks); $.post("requestforquote",{counties:jpicks}).done(function(){ window.location = base_url + "countyparcels/quoteform" }); });
url.py
urlpatterns = [ url(r'^(requestforquote)$',views.request4quote), url(r'^(quoteform)$',views.quoteform) ]
views.py
shopping_cart = 'shoppingcart' @csrf_exempt def request4quote(request,misc): try: request.session[shopping_cart] = request.post['counties'] # no exception here except exception e: print e.message try: response = httpresponse("true",content_type="text/plain") # no exception here except exception e: print e.message response = http404 return response # http: 500 if include session setting code above # error session set simple string literal ... "true"
the error occurring in response variable value.
returning http404
type object in exception, raise attributeerror
, it's exception leading exception.
from code provided above thing can think of didn't import httpresponse
.
need : from django.http import httpresponse
if doesn't work ll need provide traceback.
Comments
Post a Comment