How to display ü created in python and displayed in html?

I've created a django app in German.

I have the following in python:

error = 'Füllen Sie alle Pflichtfelder aus'
return HttpResponse(render_to_string(page.html, {'error':error}))

My page.html would be simple:

<p> {{error}} </p>

What should I do so that the letter ü can be displayed in the html? I tried writting &uuml; in the python code, but I did not work.

Many thanks in advance.


With questions like these, it helps if you describe exactly what the error is that you're seeing.

There are a couple issues with what you're doing, the biggest being that you're using strings, not unicode objects.

Here's the documentation on how to properly create a unicode object in Python

In Python, you can have two different types of strings. One uses only ASCII characters, the other uses any unicode character. You specify a unicode string by surrounding it with a u'' instead of ''. Also, by default, Python doesn't load in your source code as unicode, so you want to encode any strings you have in it (or change the encoding of the file, as shown in the link above) So your line should become:

error = u'F\u00FCllen Sie alle Pflichtfelder aus'

Then everything should work out fine!

After that, as a purely style thing, you probably want to change the last line in your view to just be:

return render_to_response(page.html, {'error':error})

which is effectively the same but a nice shortcut.

You may try {{ error|safe }} with ü as &uuml. Alternatively save the corresponding .py file as UTF-8 encoded. Hope this leads into the right direction.

Need Your Help

Capturing Rscript errors in an output file

linux r rscript

Unlike the similar command R CMD BATCH which by default produces an output file which contains any error messages which would cause the execution of a script to halt, I have not been able to find a...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.