Code

Ticket #1908: directory_name_fix.diff

File directory_name_fix.diff, 1.4 KB (added by yasar11732, 3 years ago)

Fixes comment 12

Line 
1diff --git a/django/core/management/commands/startapp.py b/django/core/management/commands/startapp.py
2index 13d6483..7612520 100644
3--- a/django/core/management/commands/startapp.py
4+++ b/django/core/management/commands/startapp.py
5@@ -3,6 +3,9 @@ import os
6 from django.core.management.base import copy_helper, CommandError, LabelCommand
7 from django.utils.importlib import import_module
8 
9+# to check if upper level directory is really a django project
10+std_project_files = ("manage.py","urls.py")
11+
12 class Command(LabelCommand):
13     help = "Creates a Django app directory structure for the given app name in the current directory."
14     args = "[appname]"
15@@ -21,8 +24,13 @@ class Command(LabelCommand):
16         # which should be the full path of the project directory (or the
17         # current directory if no directory was passed).
18         project_name = os.path.basename(directory)
19+       
20         if app_name == project_name:
21-            raise CommandError("You cannot create an app with the same name"
22+            for filename in std_project_files:
23+                if not os.path.isfile(os.path.join(project_name,filename)):
24+                    break
25+            else:
26+                raise CommandError("You cannot create an app with the same name"
27                                " (%r) as your project." % app_name)
28 
29         # Check that the app_name cannot be imported.