News for hackers. Stuff that matters.
Re:Django 3.1 by jungletime on Tuesday August 04, 2020 @01:31PM (#24052379)
Something I wish that Django did was user defined functions in the template. It has for loops, which is good but it forces you to write the html in top to bottom procedural manner.

It would be far better to be able to define a function that you can call for bits of html code that might repeat in the same template.

Since I stopped using Django at 1.6 does the new version let you define functions in the templates?

Re:Django 3.1 by __alexs on Tuesday August 04, 2020 @01:34PM (#24052417)
Re:Django 3.1 by jungletime on Tuesday August 04, 2020 @01:51PM (#24052576)
That isn't as nice to having a function inside the same file you can call over, IMHO.

Also lets say you define a block for rendering a button with a different color. Then use 20 different buttons on one page.

Does that mean that the block code would need to be loaded from a file 20 times and parsed each time. Seems like huge performance hit to do it that way.

Is there a technical reason why you can't have a function in the same file.

Am I misunderstanding how it works?

Re:Django 3.1 by madelyn on Tuesday August 04, 2020 @04:27PM (#24054154)
I wrote a little library that does exactly this, though it's framework agnostic. I agree being able to use components in Python for webdev is nice.

It's called "dashml" on PyPi if anyone is interested. I mostly use it in Django and haven't worked on it lately cause of $DAYJOB though.

Re:Django 3.1 by drcongo on Tuesday August 04, 2020 @01:44PM (#24052508)
Django has full Jinja support these days which is vastly preferable.
Re:Django 3.1 by jungletime on Tuesday August 04, 2020 @01:54PM (#24052598)
Can you write functions in Jinja?
Re:Django 3.1 by mrigor on Tuesday August 04, 2020 @01:58PM (#24052639)
yeah, it supports macros