Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#18496 closed Uncategorized (invalid)

wsgi.py script need to add project path to sys.path

Reported by: medhat.gayed@… Owned by: nobody
Component: Uncategorized Version: 1.4
Severity: Normal Keywords: wsgi, sys.path
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by aaugustin)

In Django 1.4, the default wsgi.py script should append the project path to sys.path in order for the apache wsgi process to be able to import from the project apps.

Something along these lines:

import sys

path = os.path.abspath(os.path.join(__file__, '..', '..'))

if path not in sys.path:
    sys.path.append(path)

Change History (3)

comment:1 Changed 3 years ago by aaugustin

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

AFAIK the new WSGI script was precisely introduced to eliminate such sys.path hacks.

There's probably a problem with your PYTHONPATH and/or the way you import your project apps.

Here are the recommended support channels.

comment:2 follow-up: Changed 3 years ago by carljm

Some WSGI servers (Apache/mod_wsgi in particular) do still require you to explicitly add the path, but that should be done via your Apache configuration using the WsgiPythonPath directive. The documentation on using Django with mod_wsgi includes this.

comment:3 in reply to: ↑ 2 Changed 3 years ago by anonymous

Replying to carljm:

Some WSGI servers (Apache/mod_wsgi in particular) do still require you to explicitly add the path, but that should be done via your Apache configuration using the WsgiPythonPath directive. The documentation on using Django with mod_wsgi includes this.

Thank you so much carljm, your comment was very enlightening to me.

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