开发者

How to eliminate a django form's prefix when rendering only the field's name, but keeping everything else untouched

In some views of my Django app, two instances of the same form are rendered, one is included via a context processor, and the other is included by the view. The only difference between the two forms are the styling and position, they have the same fields and submit to the same view.

Then I notices that the IDs of the elements are the same, and some functionality, like the label click that focus the corresponding field, behaves wrong, like focusing the same field on the other form. Then I added a form prefix to the first form and of course the labels worked again.

But the prefix is also applied to the fields names (besides the IDs), and therefore, the view that get the submitted data didn't work, since the form instance was initialized without the prefix. Also, the query string looks even weirder :(

I'm looking for a solution that keeps the original fields names, not prefixed, and still use prefixed HTML IDs, so the view keeps working unchanged. Or any other way of rendering two f开发者_StackOverfloworms with isolated ids but the same field names.


using prefix is useful to have several Django forms in a single <form> element.

If you want to have more than one <form> element, you may use Formsets.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜