views:

179

answers:

2

I've found a similar question here, but I'm looking for more general solutions.

As it is now, when Django generates anykind of HTML for you (this mainly happens when generating forms), it uses self-closing tags by default i.e. <br /> instead of <br>. <br /> is valid XHTML and I think HTML5 also, but it's not valid HTML4.

Is there any clean way to override this? Or is it better to write django sites in XHTML or HTML5 instead?

+1  A: 

There was a whole series of discussions on this when development for 1.2 kicked off, with a range of solutions proposed, but no general way forward was agreed.

But see Simon Willison's Django-HTML project for one possible solution.

Daniel Roseman
Hmmm... Thanks. The more I read through the discussion the more potential pitfalls I uncover. I might stick to XHTML or HTML5 after all cause it seems the far simpler option.
Monika Sulik
+1  A: 

You can rewrite entirely the way django output HTML for you. E.G : for the form, you can :

  • choose between output using table, p or li by using the property "as_xxx".
  • print the form label by label, choosing the tag wrappers.
  • use widget to define how a form piece will print to HTML.

Of course you need the new forms to do so, and there for use Django 1.X.

e-satis
Thanks - this does indeed solve a certain chunk of the problem, but there are still other areas (like the csrf token) that I'd have to resolve seperately *sigh*
Monika Sulik
isn't csrf token only an empty string before V1.2 ?
e-satis
Ah, my mistake, you are probably talking about the legacy method with 'django.middleware.csrf.CsrfResponseMiddleware'
e-satis