Opened 7 years ago

Closed 7 years ago

Last modified 4 years ago

#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: UI/UX:


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)

Change History (2)

comment:1 Changed 7 years ago by ubernostrum

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to wontfix
  • Status changed from new to closed

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).

comment:2 Changed 4 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 deleted

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