Skip to content

Instantly share code, notes, and snippets.

@bekatom
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save bekatom/85e838446111850eb96f to your computer and use it in GitHub Desktop.

Select an option

Save bekatom/85e838446111850eb96f to your computer and use it in GitHub Desktop.
django & JS client >json
function get_hotel_price(id){
$.ajax({
data : { 'id' : id},
type : 'GET',
url : '/hotels/price/',
success : function(responce){
rs = JSON.parse(responce);
$('#id_price').val(rs.price);
}
});
}
from django.shortcuts import HttpResponse
from django.contrib.auth.decorators import login_required
@login_required()
def get_hotel_price(request):
id = request.GET['id']
if id is not None:
h = Hotels.objects.get(pk=id)
data = {'price': h.price}
return HttpResponse(json.dumps(data))
##### URL #############
hotels_urlpatters = [
url(r'^price/$', get_hotel_price),
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment