On Dec 18, 2006, at 10:52 PM, Denis Frère wrote:
>
> I've just found a bug that made me searching for hours... I'll tell  
> you
> the story in case it could help someone else.
>
> I got a strange behaviour with Django views recently : some pages of a
> website I'm developping were empty apart from the template. That is,
> the template was called but there was no data to fill the variables.
> The stranger is that a same view code was OK for some pages and bad  
> for
> other pages. It happened with generic views and even with flatpages.
>
> After a long search, I discovered the problem : I had written a buggy
> template context processor. Depending on the request.path, I was
> returning or not a dictionary. When I was returning the dictionary,
> everything was OK, but when not, my templates were empty.
>
> OK, I'm guilty. I knew I had to return a dictionary, but I don't
> appreciate having had no clues to find the bug. I love Python because
> he's generally kind with me, telling me where I made errors. When
> Django fails silently, it makes things much harder for bad programmers
> like me.
>
> In conclusion, a question for the developpers : wouldn't it be better
> to throw exceptions when being in debug mode and fail silently only
> when debug mode is off ?


You can always use the TEMPLATE_STRING_IF_INVALID variable to display  
a string in place of non-existent variables. But you should be aware  
of this warning, which is why it should not be turned on for general  
development:

"Many templates, including those in the Admin site, rely upon the  
silence of the template system when a non-existent variable is  
encountered. If you assign a value other than '' to  
TEMPLATE_STRING_IF_INVALID, you will experience rendering problems  
with these templates and sites.

Generally, TEMPLATE_STRING_IF_INVALID should only be enabled in order  
to debug a specific template problem, then cleared once debugging is  
complete."

You may ask, why would anybody rely on a non-existent variable in  
their template? Think of the {% if xxx %} tag. If you want a section  
of html to display, you set the variable, if not, you don't need to  
set anything.

The above paragraph is from:

http://www.djangoproject.com/documentation/templates_python/#how- 
invalid-variables-are-handled

Don



--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to