Skip to content

Use Django's module loading rather than __import__ #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 19, 2016

Conversation

andrewyoung1991
Copy link
Contributor

import doesn't deal well with dotted paths, in my instance my root url conf is in a few levels ROOT_URLCONF = "appname.config.urls". unfortunately, for import this means that just appname is imported, but config.urls is loaded and no other modules in between are usable. Switching to Django's import_string method allows importing the final module in the path string, in my case the equivalent would be from appname.config import urls.

__import__ doesn't deal well with dotted paths, in my instance my root url conf is in a few levels "appname.config.urls". unfortunately, for __import__ this means that just `appname` is imported, but `config.urls` is loaded and no other modules in between are usable. Switching to Django's `import_string` method allows importing the final module in the path string, in my case the equivalent would be `from appname.config import urls`.
@manosim manosim added this to the Release 0.0.7 milestone Feb 19, 2016
@manosim
Copy link
Owner

manosim commented Feb 19, 2016

Looks good to me @andrewyoung1991!

As the docs say:

Imports a dotted module path and returns the attribute/class designated by the last name in the path. Raises ImportError if the import failed.

Thank you for contributing 👍

manosim pushed a commit that referenced this pull request Feb 19, 2016
Use Django's module loading rather than __import__
@manosim manosim merged commit a1ad2d7 into manosim:master Feb 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants