Tuesday, January 14, 2014

Re: Encoding UTF 8 (añ,etc) and datetime function

I had the some problem (Português tem seus acentos :) )

  From the Python reference:
http://www.python.org/dev/peps/pep-0263/
    Python will default to ASCII as standard encoding if no other      encoding hints are given.        To define a source code encoding, a magic comment must      be placed into the source files either as first or second      line in the file, such as:              # coding=<encoding name>        or (using formats recognized by popular editors)              #!/usr/bin/python            # -*- coding: <encoding name> -*-        or              #!/usr/bin/python            # vim: set fileencoding=<encoding name> :




On Tue, Jan 14, 2014 at 4:12 PM, David Pineda <dahalpi@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)

Whit utf8

SyntaxError at /time/plus/99/

Non-ASCII character '\xc3' in file /home/david/Documents/Django/tutorial2/base1/base1/views.py on line 8, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details (views.py, line 8)
Request Method: GET
Request URL: http://127.0.0.1:8000/time/plus/99/
Django Version: 1.5.5
Exception Type: SyntaxError
Exception Value:
Non-ASCII character '\xc3' in file /home/david/Documents/Django/tutorial2/base1/base1/views.py on line 8, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details (views.py, line 8)
Exception Location: /home/david/Documents/Django/tutorial2/base1/base1/urls.py in <module>, line 2
Python Executable: /usr/bin/python
Python Version: 2.7.5
Python Path:
['/home/david/Documents/Django/tutorial2/base1',   '/usr/lib/python27.zip',   '/usr/lib64/python2.7',   '/usr/lib64/python2.7/plat-linux2',   '/usr/lib64/python2.7/lib-tk',   '/usr/lib64/python2.7/lib-old',   '/usr/lib64/python2.7/lib-dynload',   '/usr/lib64/python2.7/site-packages',   '/usr/lib64/python2.7/site-packages/PIL',   '/usr/local/lib64/python2.7/site-packages',   '/usr/local/lib/python2.7/site-packages',   '/usr/lib64/python2.7/site-packages/gtk-2.0',   '/usr/lib/python2.7/site-packages',   '/usr/lib64/python2.7/site-packages/wx-2.8-gtk2-unicode']
Server time: Tue, 14 Jan 2014 12:12:55 -0600

The code whituot 'á'-->a

from django.http import Http404, HttpResponse
import datetime
# coding: utf-8

def hello(request):
    return HttpResponse("Hello world")
def home_page(request):
    return HttpResponse("Pagina de Inicio")
..
.
.
It's work



El martes, 14 de enero de 2014 13:21:20 UTC-3, Erik Cederstrand escribió:
Den 14/01/2014 kl. 17.04 skrev David Pineda <dah...@gmail.com>:

> Hello, i'm beginning to learn python+django and i'm doing that handbook https://github.com/jacobian/djangobook.com/blob/master/chapter03.rst
> In the example whit datetime i have a problem when i active the utf-8 encondig because i use á,ñ, etc (i'm chilean and we talk in spanish)
> So, when i deactive it's works fine, but in the future when i do something more i will need the utf8 enconding and all functionalities like datetime working and i don't know  yet how to do to make work together that,

Please post the code where you are trying to use non-ASCII characters. What did you try, and what is the exact error message you see?

Thanks,
Erik

--
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+unsubscribe@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/67d88b83-2be9-4295-93f5-c285f760736c%40googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

--
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+unsubscribe@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/CAFpSzTNQdOfkieFRDPS6N5DxWvtty%3DdPfc01SCFrOi7W2iLfEQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate