Monday, May 18, 2020

creating a utility script inside a django app; relative import woes

I'm a relatively new Django user.
I'm running into a problem related to relative imports.
I have a project and app set up the usual way

mysite
-- myapp
---- __init__.py
---- all the modules and templates in myapp including one that contains the definition of MyClass
-- mysite
---- __init__py
---- all of the other the standard stuff inside mysite

The project works.

I want to create a utility script that makes use of a module in myapp
I want to be able to run this utility script from the command line.

When I try to import MyClass from mymodule via
from .mymodule import MyClass

I get
ImportError: attempted relative import with no known parent package

If I leave out the dot before mymodule
I get the same error but for another module in myapp that mymodule tries to import,

I suspect I'm trying to do something I'm not supposed to do but don't know what.
If it helps, I'm doing this in vscode


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/68cd1977-b2bb-44e7-9b93-6d6a928764a5%40googlegroups.com.

No comments:

Post a Comment