django messages framework

59 views
Skip to first unread message

Anand Kumria

unread,
Sep 30, 2011, 4:01:25 AM9/30/11
to django-d...@googlegroups.com
Hi,

Sparked by a discussion with friends on common failing in web
development, one common one is encoding HTML in the code.

There are efforts underway to address this within core Django (related
to widgets and forms) but a pattern I've noticed in some of my project
is that messages in response to actions have HTML encoded within the
Django code.

Obviously it isn't hard to modify things so that instead of a fixed
message, these projects load a template and then render that to a
string -- leaving the HTML to others.

My idea is that Django will allow you to shoot yourself but should
promote as much best practice (easily) as it can.

With that in mind I think a nice extension to the messages framework
would be to allow a template to be specified instead of a string.

Before I create a patch / ticket to do this, I was wondering if anyone
had any thoughts or opinions about it first (since having a discussion
on trac can be difficult).

Regards,
Anand

Gabriel Hurley

unread,
Sep 30, 2011, 2:04:38 PM9/30/11
to django-d...@googlegroups.com
I'm a fan of the idea, with the caveat that it can't break any backwards-compatibility with the current syntax. As such, that could either entail reworking the current methods that add messages to accept a template string as a keyword argument (and making the positional "message" argument optional), or implementing it as a separate shortcut to allow further flexibility.

All the best,

    - Gabriel

Wim Feijen

unread,
Sep 30, 2011, 6:34:02 PM9/30/11
to Django developers
Using render_to_string, you can use a template, and it is backwards
compatible. Would that work?

Wim
Reply all
Reply to author
Forward
0 new messages