开发者

Django: how to pass form variable to simple tag in template

开发者 https://www.devze.com 2023-01-03 13:28 出处:网络
I am trying to do some custom things in Django comments form. I have simple tag named \"get_flatpage_by_id\" that returns flatpage model data as array. This is working I expected:

I am trying to do some custom things in Django comments form. I have simple tag named "get_flatpage_by_id" that returns flatpage model data as array. This is working I expected:

{% get_flatpage_by_id 14 as page %}

It's returning flatpage that ID is 14. But this is not working, if I try to pass {{ form.object_pk.data }} (that returns 14). This is how it should look like:

开发者_如何学C

{% get_flatpage_by_id form.object_pk.data as page %}

Simple tag receives value "form.object_pk.data" (string), not 14. I don't know how to tell Django that "form.object_pk.data" is variable, not a string!


Nevermind, my friend showed solution...

In filter I can read all data passed to template, so I received form object and data I needed.

0

精彩评论

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