Django template and the locals trick

后端 未结 8 1407
不思量自难忘°
不思量自难忘° 2020-12-02 10:43

The django books gives the local trick in order to avoid to type a long list of parameters as context dictionnary

http://www.djangobook.com/en/2.0/chapter04/

8条回答
  •  渐次进展
    2020-12-02 10:53

    I often thought of doing the following, but I am not sure if it is really helpful.

    class MyStruct(object):
         pass
    
    def my_view(request, id):
        c = MyStruct()
        c.customer = ..
        c.invoice = ..
        c.date = ..
        return render_to_response('xxx,html',c.__dict__)
    

提交回复
热议问题