Do Django Apps have reserved/illegal names? Imports/makemigrations don't work based on app name

Viewed 292

My Django project has several apps, which all have no issue, with the exception of the app called platform. To import from this app, I need to use the full path, rather than being able to import it directly, for example:

from app.models import MyModel # Doesn't work for platform app, but it does for others

vs

from project_root.app.models import Mymodel # Have to do this only for platform app

I changed the name from platform to theplatform and it worked. Imports worked without full paths, the makemigrations starting finding the models. The only thing that changed was the name of the app.

Each of my apps have an apps.py, with a class inheriting from AppConfig with the name of the app, and all of them are in installed apps. I've also made sure adding/removing init.py doesn't mess with anything. I feel pretty certain the only variable here is the name of the app.

Are there reserved or illegal app names in Django? If there are is there a place I can read up on it if there are? The only restriction I'm aware of is not having dashes in the name.

1 Answers

platform[1] is a built-in module in python and is likely showing up ahead of your local platform module on your import paths.

You'd need to examine your import paths by looking at sys.path (import sys) to say for certain. Normally '' comes first and is your current working directory, so all local modules override/shadow system modules.

You could make modifications to your import path either using the environment variable PYTHONPATH or by changing sys.path to make your local platform be the first one found, but I'd recommend not using that name. There may be packages you use in the future that expect to get the system module when they import platform and won't work.

[1]: http://docs.python.org/3/library/platform.html)

Related