コード例 #1
0
def render_to_response(template_name, dictionary=None,
        context_instance=None):
    if isinstance(template_name, (list, tuple)):
        template = select_template(template_name)
    else:
        template = get_template(template_name)

    dictionary = dictionary or {}
    if context_instance is None:
        context_instance = Context(dictionary)
    else:
        context_instance.update(dictionary)
    data = {}
    [data.update(d) for d in context_instance]
    data = uni_str(data, encoding=settings.DEFAULT_CHARSET, key_convert=False)
    return HttpResponse(template.render(**data))
コード例 #2
0
def json_response(data, check=False):
    encode = settings.DEFAULT_CHARSET
    if check:
        if not is_ajax_data(data):
            raise SimpleAjaxException, 'Return data should be follow the Simple Ajax Data Format'
    return HttpResponse(simplejson.dumps(uni_str(data, encode)))
コード例 #3
0
ファイル: ajax.py プロジェクト: BGCX261/zipbook-svn-to-git
def json_response(data, check=False):
    encode = settings.DEFAULT_CHARSET
    if check:
        if not is_ajax_data(data):
            raise SimpleAjaxException, "Return data should be follow the Simple Ajax Data Format"
    return HttpResponse(simplejson.dumps(uni_str(data, encode)))