views:

20

answers:

1

I have multiple forms in a Django project. I was trying to use the Django provided as_p for form displaying due to its simplicity but client wants the error list below the field. Django's as_p prints it above the field label. I rather not add a field printing loop in every template just for this small change. It seems like the least efficient way to go about it.

Wanted to know what would other Django coders recommend for this. I was thinking there exists at least 3 options:

-Customizing the Form object. This seems the most viable solution. Anyone know of any downsides to this?

-Including a template which just handles form displaying. The problem is, this template must assume that the form is named a certain name. How about if I have multiple forms being passed with different names? Does anyone know how to address this issue?

-Perhaps a custom filter? A quick Google search leads me to believe this is not a viable option but perhaps someone has information to the contrary.

Examples would be greatly appreciated!

+2  A: 

Including a template which just handles form displaying. The problem is, this template must assume that the form is named a certain name. How about if I have multiple forms being passed with different names? Does anyone know how to address this issue?

You could include your form template inside of with block and thus be able to send a value for a from name.

You could also leave out the <form> tags from your form body template and just put them around include.

I think these would be the easies solutions, and with taking advantage of template inheritance you could create quite flexible forms.

rebus
Ah, very nice. I was not aware of the with tag. Thank you for the very elegant solution. Much obliged!
Nimmy Lebby
+1, nice solution. Thanks.
ars