开发者

json serializer with jquery

开发者 https://www.devze.com 2023-03-18 03:20 出处:网络
my question is want to display my date in %B %d format python actually i done with with my conversion of date and now the problem is when is pass that array (today_data) to json serializer it wont wo

my question is want to display my date in %B %d format python actually i done with with my conversion of date and now the problem is when is pass that array (today_data) to json serializer it wont work.here is my code as follows: im new to django can u help thanx in advance.

def today_event(request):
    today_event = scene()

    now = datetime.now()
    now = str(now.strftime("%d %B %Y"))
    current_date_time = datetime.strptime(now,"%d %B %Y")
    today_event = scene.objects.filter(startdate=current_date_time)

    today_data = []
    for today in today_event:
        today.startdate = today.start开发者_如何学JAVAdate.strftime("%B %d")
        today_data.append(today)    

    json_serializer = serializers.get_serializer("json")()
    data_event = json_serializer.serialize(today_data, ensure_ascii=False)
    return HttpResponse(data_event)


The problem has nothing to do with dates. It is simply that the serializers module is just for querysets. You have a standard list, so just use the basic simplejson module:

from django.utils import simplejson
data_event = simplejson.dumps(today_data)
0

精彩评论

暂无评论...
验证码 换一张
取 消