from django.shortcuts import render
from django.http import HttpResponse, Http404, HttpResponseRedirect
from django.template import RequestContext
from django.shortcuts import render_to_response, get_object_or_404
from django.core import serializers
from example.my_app.models import Example
def example_cat(request, in_category):
examples = list( Example.objects.filter(category = in_category) )
variables = RequestContext( request,
{
'examples': examples,
})
return render_to_response('Example/Example.html', variables)
def example_cat_json(request, in_category):
try:
examples = list( Example.objects.filter(category = in_category) )
data = serializers.serialize('json', examples)
print data
return HttpResponse(data, mimetype='application/javascript')
except Category.DoesNotExist:
print "Error: Category does not exist."
message = "Error: Category does not exist."
return HttpResponse(message)
No comments:
Post a Comment