This question might reveal a gaping hole in my knowledge of json queries, but I'm trying to get json data to display on a view with the following URL.
http://localhost:8000/structures/hydrants/json?id=%3D2/
Here's my URL regex:
url(r'^hydrants/json\\?id=(?P<hydrant_id>\d+)/$', views.hydrant_json, name='hydrant_json'),
and the view:
def hydrant_json(request, hydrant_id):
hydrant = get_object_or_404(Hydrant, pk=hydrant_id)
data = [hydrant.json()]
return HttpResponse(json.dumps(data), content_type='application/json')
Obviously, the question mark is throwing it off, because if I make the regex
url(r'^hydrants/json/id=(?P<hydrant_id>\d+)/$', views.hydrant_json, name='hydrant_json'),
then the following URL will work:
http://localhost:8000/structures/hydrants/json/id%3D2/
Thanks in advance!