When using Django for html templating how do I create good html markup formatting.
I am trying to make use of content blocks. But the content blocks show up at different levels of indentation in different templates. How do I get the content blocks to show indented like it would be if someone was to hand write the html.
I am having the same problem with newlines; I can smash all the blocks together in the template. At that point the html looks better, but the templates are unmaintainable.
I guess the question is how to you create pretty html markup with the django templating system?
I am surprised by the answers so far. I find that nicely formatted HTML aids in writing the corresponding CSS and JavaScript. As well as making it easier to add content later on.
It can generate any text-based format (HTML, XML, CSV, etc.).
Using the include tag in Django requires fewer tags than using the Django extends tag. (1) First, create the Django template you want to be included in other templates. Create a new folder called includes. This folder will hold all of the HTML files we want to include within other Django templates.
Django is a tool to generate Web pages It can do more than that, but's that the basics of it. Writting HTML code by hand is very tedious, not very efficient, and limited : you can't make pages that adapts to the person who asks for it such as a user page or a search page.
You can't use Django's template tags from your Javascript code if that's what you mean. All the Django variables and logic stop existing after the template has been rendered and the HttpResponse has been sent to the client.
Christian S. Perone from Pyevolve has exactly what you're looking for. He uses middleware to intercept the HTTPResponse object and run it through BeautifulSoup.
I'd imagine that your site will suffer a slight performance hit, though. I recommend running some benchmarks before deploying this middleware to a production site.
You can override the NodeList's render method as I've done. See my question with working code:
Proper indentation in Django templates (without monkey-patching)?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With