Fixed #9092 -- Improved validation of app/project names by startapp/startproject so that it doesn't allow names to start with a number.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9043 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
772639c692
commit
883aa6b9c8
|
@ -194,8 +194,13 @@ def copy_helper(style, app_or_project, name, directory, other_name=''):
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
other = {'project': 'app', 'app': 'project'}[app_or_project]
|
other = {'project': 'app', 'app': 'project'}[app_or_project]
|
||||||
if not re.search(r'^\w+$', name): # If it's not a valid directory name.
|
if not re.search(r'^[_a-zA-Z]\w*$', name): # If it's not a valid directory name.
|
||||||
raise CommandError("%r is not a valid %s name. Please use only numbers, letters and underscores." % (name, app_or_project))
|
# Provide a smart error message, depending on the error.
|
||||||
|
if not re.search(r'^[_a-zA-Z]', name):
|
||||||
|
message = 'make sure the name begins with a letter or underscore'
|
||||||
|
else:
|
||||||
|
message = 'use only numbers, letters and underscores'
|
||||||
|
raise CommandError("%r is not a valid %s name. Please %s." % (name, app_or_project, message))
|
||||||
top_dir = os.path.join(directory, name)
|
top_dir = os.path.join(directory, name)
|
||||||
try:
|
try:
|
||||||
os.mkdir(top_dir)
|
os.mkdir(top_dir)
|
||||||
|
|
Loading…
Reference in New Issue