#10703 closed (wontfix)
Helper for importing modules from installed apps
Reported by: | Archatas | Owned by: | nobody |
---|---|---|---|
Component: | Core (Other) | Version: | 1.1-beta |
Severity: | Keywords: | reusable utility extensible import dynamic | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
It would be really convenient to create extensible and reusable apps, if there was a simple way to import dynamically from an installed app (without defining the full path).
For example, there could be the following function defined somewhere in django.utils or django.db.models:
from django.db import models from django.utils import importlib def import_installed(path): """ Imports a module from an installed app >>> import_installed("myapp.forms") <module 'myproject.apps.myapp.forms'> """ app_name, module = path.split(".", 1) app = models.get_app(app_name) return importlib.import_module(app.__name__[:-6] + module)
Note:
See TracTickets
for help on using tickets.
I don't really see the utility of this -- a properly-written Django application is just a Python module, and is importable the same as any other Python module. It's not like that module is suddenly going to have a different path (and if it does, you're doing something wrong).