Hyphen in django app

django, django-cms, python

Solution

You can do this:

import importlib
module = importlib.import_module('.module', 'my-app')

See documentation for more info https://docs.python.org/3/library/importlib.html#importlib.import_module

Edit: This is not a Django specific issue, it is that in Python (and in most other programming languages) '-' (hyphen) can't be used in variable names (As '-' is the subtraction operator).

Problem

Well I stumbled upon a problem with imports and a Django app that has a hyphen in its name. As far as I know hyphens aren't even allowed in Django app names but it's still there and the website runs without errors. I have absoltuely no idea of how the app was created since the project already existed when I started working on it. (It's a Django CMS project if that changes anything btw) Now the problem is that when I want to import something in the shell or in a project I can't just write `from my-app import module` since it always throws an error because of the hypen. Also in the `INSTALLED_APPS` it is listed with the hypen `INSTALLED_APPS = ('my-app')` So how can I actually fix this and make it useable? I thought about renaming but I don't really know the consequences and I also don't really want to break anything in the CMS (I'm still learning Django and the CMS is very new to me)

Original source