Need to convert a string to int in a django template

前端 未结 6 1043
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-27 04:58


I am trying to pass in url parameters to a django template like this...

response = render_to_string(\'persistConTemplate.html\', request.GET)
         


        
6条回答
  •  悲哀的现实
    2020-11-27 05:49

    You should add some code to your view to unpack the GET params and convert them to the values you want. Even if numItems were an integer, the syntax you're showing wouldn't give you the output you want.

    Try this:

    ctx = dict(request.GET)
    ctx['numItems'] = int(ctx['numItems'])
    response = render_to_string('persistConTemplate.html', ctx)
    

提交回复
热议问题