Skip to content

Commit

Permalink
Stop throwing custom ImportError
Browse files Browse the repository at this point in the history
This was necessary under python 2, but now that python 3 supports
exception chaining, the underlying `ImportError` won't be masked by the
other exceptions.

I considered augmenting the error message to mention checking in the
path / venv, but these days I think people will naturally google for
`ImportError` and find plenty of helpful context from StackOverflow etc.

Such as this very question/answer:
https://stackoverflow.com/questions/14013728/django-no-module-named-django-core-management
  • Loading branch information
jeffwidman authored and rbarrois committed Oct 28, 2022
1 parent edb6c2e commit e0f0c0f
Showing 1 changed file with 1 addition and 15 deletions.
16 changes: 1 addition & 15 deletions examples/django_demo/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,5 @@

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_demo.settings")
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django # noqa: F401
except ImportError:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
raise
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)

0 comments on commit e0f0c0f

Please sign in to comment.