startapp.py 928 B

12345678910111213141516171819202122232425
  1. from importlib import import_module
  2. from django.core.management.base import CommandError
  3. from django.core.management.templates import TemplateCommand
  4. class Command(TemplateCommand):
  5. help = ("Creates a Django app directory structure for the given app "
  6. "name in the current directory or optionally in the given "
  7. "directory.")
  8. def handle(self, app_name=None, target=None, **options):
  9. self.validate_name(app_name, "app")
  10. # Check that the app_name cannot be imported.
  11. try:
  12. import_module(app_name)
  13. except ImportError:
  14. pass
  15. else:
  16. raise CommandError("%r conflicts with the name of an existing "
  17. "Python module and cannot be used as an app "
  18. "name. Please try another name." % app_name)
  19. super(Command, self).handle('app', app_name, target, **options)