On Tue, Jan 14, 2014 at 6:12 PM, David Pineda <
dah...@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