Opened 14 months ago

Closed 14 months ago

Last modified 14 months ago

#22007 closed Cleanup/optimization (fixed)

Make import paths more consistent in documentation

Reported by: kinjal.dixit@… Owned by: numerodix
Component: Documentation Version: 1.6
Severity: Normal Keywords: import module, import script, nlsprint14
Cc: numerodix Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

I am getting thrown by the documentation (https://docs.djangoproject.com/en/1.6/topics/class-based-views/intro/#using-class-based-views), when they give this example:

from django.http import HttpResponse
from django.views.generic.base import View

class MyView(View):

def get(self, request):

# <view logic>
return HttpResponse('result')

For the first import, they are specifying only the folder names and omitting the actual python script which contains the definition of class HttpResponse, which is response.py. Here they are relying on the __init__.py to work.

For the second import, they are not relying on the __init__.py and going all the way to specify the python script in which the class View is defined, which is base.py.

If the first way is preferred, then the second import should be written as:

from django.views.generic import View

If the second way is preferred, then the first import should be written as:

from django.http.request import HttpRequest

I know that both are acceptable. I am just wondering why both are being used and not just one style. I think this is important because this will be what people will be writing in the code.

I would very much love to see this (and other occurrences of this) to be identified and cleaned up.

Change History (6)

comment:1 Changed 14 months ago by AeroNotix

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Is this really a big deal?

comment:2 Changed 14 months ago by aaugustin

Yes, it'd be nice to recommend a consistent import style.

comment:3 Changed 14 months ago by timo

  • Summary changed from Mixed import styles (possible OCD on my part) to Make import paths more consistent in documentation
  • Triage Stage changed from Unreviewed to Accepted

I think using the "convenience imports" (e.g. from django.http import HttpResponse) is probably the way to go.

comment:4 Changed 14 months ago by numerodix

  • Cc numerodix added
  • Keywords nlsprint14 added
  • Owner changed from nobody to numerodix
  • Status changed from new to assigned

comment:5 Changed 14 months ago by Baptiste Mispelon <bmispelon@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In d399731bf29bf842c756a77ff8a58706bac3d65f:

Fixed #22007 -- Fixed cbv docs - make imports consistent

Thanks to trac user kinjal.dixit for the report.

comment:6 Changed 14 months ago by Baptiste Mispelon <bmispelon@…>

In 4f6ff7ee85be1105b5ab78ac1bbe17a4c8c24d4e:

[1.6.x] Fixed #22007 -- Fixed cbv docs - make imports consistent

Thanks to trac user kinjal.dixit for the report.

Backport of d399731bf29bf842c756a77ff8a58706bac3d65f from master.

Note: See TracTickets for help on using tickets.
Back to Top