On Tue, Jan 14, 2014 at 6:12 PM, David Pineda <daha...@gmail.com> wrote:
>
> The code:
>
> from django.http import Http404, HttpResponse
> import datetime
> # coding: utf-8
>
> def hello(request):
>     return HttpResponse("Hello world")
> def home_page(request):
>     return HttpResponse("Página de Inicio")
> def current_datetime(request):
>     now = datetime.datetime.now()
>     html = "<html><body>It is now %s.</body></html>" % now
>     return HttpResponse(html)
> def hours_ahead(request, offset):
>     try:
>         offset = int(offset)
>     except ValueError:
>         raise Http404()
>     dt = datetime.datetime.now() + datetime.timedelta(hours=offset)
>     html = "<html><body>In %s hour(s), it will be %s.</body></html>" % 
> (offset, dt)
>     return HttpResponse(html)

Python needs to be told that a string can hold unicode by declaring it
as a unicode string. Then, you can put anything you like in to it. You
do this by putting a u before the opening quote of the string.

Eg, this is wrong, as it does not use a unicode string

def home_page(request):
    return HttpResponse("Página de Inicio")

This would be the correct version:

def home_page(request):
    return HttpResponse(u"Página de Inicio")

Do this for all strings in your project where they might contain
unicode characters, eg so in this code the strings "html" should be
marked as unicode, so should both the raw strings being passed to the
HttpResponse constructor.

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1KzvKOwzvj6Dojk%3DD8jsnNM9Wewf5qOb%3DCCK8QWbXzCWQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to