views:

51

answers:

2

I have a Django app that runs a tool and displays the results from the tool back to the user using a Django template. Sometimes Django does not display the results. It doesn't complain about anything, it just doesn't display the results. I'm guessing this is something to do with one or more of the characters in the results being illegal as far as Django is concerned. How can I get more information about what it is that Django doesn't like? Also, is there some method I can use to filter out "bad" characters? The results are normally just lots of text. They contain company confidential stuff, so I can't give an example unfortunately. I have DEBUG set to True and TEMPLATE_DEBUG set to DEBUG.

UPDATE:

I added some code to filter out all chars with a decimal value greater than 127 and it now works.

A: 

you could try using the built in django encoding methods to remove illegal characters.

from django.utils.encoding import smart_str

smart_str(your_string)
Jameso
Tried that but it didn't get rid of the illegal character(s).
swisstony
+1  A: 

If you are using the development server, put in a breakpoint with pdb and see what is going on. Or print out the string that you think has "bad" characters. If you aren't using the development server you could use the Python logging module to log the string you are getting from the tool.

You might be leaping to conclusions about the data containing bad characters. It may be something else, and without debugging further it is hard to speculate.

Brian Neal