【问题标题】:Dumps and loads in djangodjango 中的转储和加载
【发布时间】:2011-03-16 07:49:11
【问题描述】:
  from django.utils.simplejson import dumps, loads
  # -*- coding: utf-8 -*-


 def index(request):
   return render_to_response('test2/index.html')

 def add_lang(request):
   logging.debug("Got request")
   a = request.POST
    logging.debug(a["lang"])
   lang=dumps(a["lang"])
   l = Language(code=lang)
   l.save()
lang=loads(lang)

logging.debug(loads(l.code))
return render_to_response('test2/test21.html', context_instance=RequestContext(request,{'test2': l.code}))

我的问题是有什么方法可以将变量加载回模板文件中的原始格式。即,我想要一个类似于加载模板的函数。我不想在视图中这样做,因为会有很多代码更改

test21.html

    {{ test2 }}  
     //The above prints"\u0905\u0902\u0917\u094d\u0930\u0947\u091c\u093c\u0940, \u0939\u093f\u0902\u0926" 

【问题讨论】:

    标签: python django django-views django-templates


    【解决方案1】:

    不写custom filter

    【讨论】:

      猜你喜欢
      • 2011-08-26
      • 2022-12-08
      • 2021-02-16
      • 1970-01-01
      • 2010-12-31
      • 2021-03-04
      • 2020-01-26
      • 2011-11-07
      • 2013-12-16
      相关资源
      最近更新 更多