Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recommended practice for using import_module in django >= 1.8

In one of my django tests, I use django.utils.importlib.import_module similarly to how it is used here.

On upgrading to django 1.8, I get a deprecation warning

test_views.py:20: RemovedInDjango19Warning: django.utils.importlib will be removed in Django 1.9.
  from django.utils.importlib import import_module

Is the recommended practice now to use import_module from importlib in the standard library (which seems to work fine)? Or is the recommended practice to avoid using import_module entirely?

like image 818
mjandrews Avatar asked Apr 28 '15 23:04

mjandrews


2 Answers

Based on the documentation (found by looking at the django deprecation timeline for 1.9 and following the link), your first suggestion seems to be correct: developers should use the standard importlib that is part of the standard library.

like image 63
eykanal Avatar answered Sep 27 '22 22:09

eykanal


Yes, django.utils.importlib.import_module is effectively the same thing as importlib.import_module. As long as you're not targeting a version of Python before 2.7, it is okay to just use importlib.import_module.

like image 45
mipadi Avatar answered Sep 27 '22 22:09

mipadi