Tuesday, August 11, 2015

Re: How to use Django 1.8.2 with Python 2.7?

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBCAAGBQJVyjGqAAoJEC0ft5FqUuEhZPsP/1mTirpVuHLO0AnZwssfQhs4
Hpfw5lM1zhOAFWZ/Hi4hJuGT6lOItCMPUhvNpaXgjt0FLova9YcQbxWWcevJzlgs
Qzr6pv968n8q67Pz9zQrkVonQnjWwGGKbMsiVRDtBYu/yOp2Dc+jXi0kmrZUloet
EON6yi83n1i/Xjy+tB6OuSsAOlNVzBzrfwJEml6tGwSbJYZsS5dWAEWPa3oQJJJ+
QC/S3uWoE3nTYaV76WVVX5zZ2Jmi+Uv+s3wpMW6gLF2xwO9VDsNWAHOdFGz6VVmZ
mPHZombDKdZhiT4lCLk5U1Gn/3KbbgJ7+PBhAY79XRI31o0ARTEXhYwPVexrKXu2
Qn8wzy8/vvQloFwzugZm17l7KIDdfKGE2AcY0h+wDOl0w62Ctau3jhShfOOxgTDB
IRGuM/XADHtK/omnDvzP17UmNzKHAFcwQJUjxc0ifXFgJ5m7tWszOi+3mRHJGMgH
V4e/gy7FFbe5Xw0d7cq412LE5eT/pO+xQ9LGfuI3SbKcTwF4iTZHcDaQ0gvecPV+
cCv0faV8Ola83tFW1z5HIUHXjcNtAd+9vyq8EoOF09l7WpvqKiiWZ0EmVEwh590f
KblTFti/odtn9pDfgdlWlwRp6waWAqLev+h319m7sZXEI4SGss72WHU9TqtPcus1
LfRPDL8qUiQ81cj/7vUa
=HBkT
-----END PGP SIGNATURE-----
Hi,

On 08/11/2015 11:56 AM, jsachs@nvidia.com wrote:
> I'm studying the Django Project tutorial
> <https://docs.djangoproject.com/en/1.8/intro/tutorial01/> using Python
> 2.7 (because that's my department's current standard) and Django 1.8.2
> (because that's the current stable version).
>
> The tutorial says, "If you are still using Python 2.7, you will need to
> adjust the code samples slightly, as described in comments." What
> comments does it mean?

Python code comments, in the code samples that need adjusting. The first
example I see is in the `polls/models.py` code sample in this section:
https://docs.djangoproject.com/en/1.8/intro/tutorial01/#playing-with-the-api

See the "__unicode__ on Python 2" comments?

> The section "Playing with the API" instructs me to run the command:
>
> $ python manage.py shell
> or
>>>> import django
>>>> django.setup()
>
> Being a methodical sort, I tried both. The first works. The second gives
> me a bunch of errors, beginning with:
>
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "c:\Python27\lib\site-packages\django\__init__.py", line 17, in setup
> configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
>
> I think it's complaining about an incompatibility between Python 2.7 and
> Python 3.2.

Can't say without seeing more of the traceback. I doubt it though, since
this only executes code in Django itself, which is fully compatible with
both Python 2 and 3.

> I can evade the immediate problem by using "python manage.py shell"
> instead, but I expect further problems in short order, and I need to
> know how to fix them.
>
> So, where are these "comments" that tell me what to do? I don't see any
> in that part of the tutorial. I opened __init__.py, and there are no
> helpful comments there, either.

You don't need to adjust anything at all in Django itself to adapt to
Python 2; Django fully supports both 2 and 3. You just need to make sure
that the code you write yourself is Python 2 compatible. Where the
tutorial tells you to type some code in a file, it gives the Python 3
version, but has comments showing what needs to be adjusted for Python
2. There's nothing special you need to do until you get to those code
samples.

> I could figure this out myself, but I can't see debugging my way through
> the entire Django codebase. I'm being paid to write an application, not
> fix up Django.

You don't need to fix up Django.

> Either I'm missing the comments that the tutorial promised me, or it has
> left me in the lurch. Can someone explain, please?

Just continue with the tutorial, and read the code samples (including
comments) carefully, when you reach them.

Your issue when running `django.setup()` is probably entirely unrelated,
but in order to debug it we'd need to see the full traceback.

Carl

--
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/55CA31AA.4040707%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment