Django

Code

Ticket #4296 (closed: fixed)

Opened 1 year ago

Last modified 1 year ago

PYTHONPATH in mod_python documentation confuses almost everybody

Reported by: anonymous Assigned to: jacob
Milestone: Component: Documentation
Version: SVN Keywords: mod python, pythonpath
Cc: dev@simon.net.nz, knutin@urtete.com, Graham.Dumpleton@gmail.com Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 1

Description

http://www.djangoproject.com/documentation/modpython/

It says:

PythonPath? "/path/to/project? + sys.path"

But if you SetEnv? DJANGO_SETTINGS_MODULE project.settings, it throws this error:

EnvironmentError?: Could not import settings 'project.settings-vatle.midgard' (Is it on sys.path? Does it have syntax errors?): No module named project.settings-vatle.midgard

The docs should say that the PythonPath? should be the path to the parent dir of your project.

I don't know if this makes much sense, I'm new to django and python. It caused me some head-aches, but someone very helpful at #django pointed me in the right directon.

Thanks for all the great work!

Attachments

django-modpython.diff (1.1 kB) - added by knutin@urtete.com on 05/16/07 08:42:46.
Patch to docs/modpython.txt
modpython.diff (0.6 kB) - added by Simon G. <dev@simon.net.nz> on 07/29/07 07:17:18.

Change History

05/14/07 14:22:43 changed by knutin@urtete.com

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

Forgot my email:

knutin@urtete.com

:-)

05/15/07 17:26:39 changed by SmileyChris

  • cc set to knutin@urtete.com.
  • stage changed from Unreviewed to Accepted.

05/15/07 17:27:50 changed by SmileyChris

Thanks for the report. You're right, this should be mentioned.

If you feel up to it, why not try your hand at providing a patch? Ask on #django if you need help with this.

05/16/07 08:42:46 changed by knutin@urtete.com

  • attachment django-modpython.diff added.

Patch to docs/modpython.txt

06/07/07 13:28:23 changed by jacob

  • status changed from new to closed.
  • resolution set to duplicate.

Fixed; this is a dup of #3842.

06/07/07 13:41:30 changed by knutin@urtete.com

  • status changed from closed to reopened.
  • has_patch set to 1.
  • resolution deleted.

This is not a dup of #3842.

The patch I uploaded was applied and the problem this ticket adressed, got solved.

With your latest change, the text that caused problems got changed back to the original state before my patch.

The problem as stated in the ticket description, is that

PythonPath "['/path/to/project] + sys.path" 

tricks those new to django and python into thinking they have to use the path to their project, and ***not*** the parent dir as it should be:

PythonPath "['/your/python/path'] + sys.path"

Please have a look at the patch that I attached. I hope you will merge these changes.

07/13/07 04:30:24 changed by anonymous

Just chiming in that we get this sort of question on IRC all the time. While I don't think "/your/python/path" is any less confusing (it's already called PythonPath?!), there should definitely be a note explicitly saying that the PythonPath? should point to the parent directory of the project.

07/14/07 01:43:28 changed by Graham.Dumpleton@gmail.com

There is more wrong with the descriptions in the mod_python setup page than you think. Although the parent directory is always required to allow settings file to be picked up, in some cases the site directory also needs to be added to PythonPath?. For an analysis of this see Django user list discussion at:

http://groups.google.com/group/django-users/browse_frm/thread/24deb095a2b2e450/1c982558d464017a

Thus, not just a simple case of changing what example path is shown as explanation of when to set PythonPath? to needs to be changed as well as example of what it is set to.

07/16/07 17:49:30 changed by anonymous

  • cc changed from knutin@urtete.com to knutin@urtete.com, Graham.Dumpleton@gmail.com.

I agree with Graham that if the set of circumstances is known that causes the "two entries in PythonPath" problem to arise that it should be documented (or Django should automagically work around it). I'd also like to see a 'real world' example of setting PythonPath since neither /path/to/project nor /your/python/path make it clear to me actually what I'm trying to achieve. I think explicitly making reference to the ViewDoesNotExist exception and using the "two entries" technique to solve it would also reduce the overall quantity of pain and suffering in the world.

Sadly I am new to both Django and Python and don't really feel I can contribute a better solution. I'm trying to get better :)

07/29/07 07:17:18 changed by Simon G. <dev@simon.net.nz>

  • attachment modpython.diff added.

07/29/07 07:19:01 changed by Simon G. <dev@simon.net.nz>

  • cc changed from knutin@urtete.com, Graham.Dumpleton@gmail.com to dev@simon.net.nz, knutin@urtete.com, Graham.Dumpleton@gmail.com.
  • summary changed from Wrong path in mod_python documentation to PYTHONPATH in mod_python documentation confuses almost everybody.

This still seems to be confusing people (#5004 was a dupe). I've attached an updated patch - can other people (Graham?, knutin@..?) check this and see if there's anything else to add here.

07/29/07 07:19:25 changed by Simon G. <dev@simon.net.nz>

  • needs_better_patch set to 1.

08/14/07 23:58:07 changed by Paul Bx <pb@e-scribe.com>

Patch looks good. I'd change "should be" to "should include", since $PYTHONPATH often (as in the example) includes more than one directory.

People are still tripping over this. I think it's better to get this (much improved) wording into the docs than to succumb to a bikeshed discussion about the fine points. It can always be expanded later but this takes care of the most common point of confusion.

08/15/07 07:25:21 changed by mtredinnick

  • status changed from reopened to closed.
  • resolution set to fixed.

(In [5896]) Fixed #4296 -- Added more explanation around the PythonPath? directory setting. Based on contributions from a cast of thousands (Simon Greenhill, Paul Bissex, Graham Dumpleton, ...). Thanks, all.


Add/Change #4296 (PYTHONPATH in mod_python documentation confuses almost everybody)




Change Properties
Action