Skip to content

Instantly share code, notes, and snippets.

@VRamazing
Created August 27, 2019 05:19
Show Gist options
  • Save VRamazing/d1adf0b243605fb4f4adce09d572e537 to your computer and use it in GitHub Desktop.
Save VRamazing/d1adf0b243605fb4f4adce09d572e537 to your computer and use it in GitHub Desktop.
rename.py
import os
from django.core.management.base import BaseCommand
class Command(BaseCommand):
help = 'Renames a Django project'
def add_arguments(self, parser):
parser.add_argument('new_project_name', type=str,
help='The new Django project name')
def handle(self, *args, **kwargs):
new_project_name = kwargs['new_project_name']
# logic for renaming the files
files_to_rename = ['djecommerce/settings/base.py',
'djecommerce/wsgi.py', 'manage.py']
folder_to_rename = 'djecommerce'
for f in files_to_rename:
with open(f, 'r') as file:
filedata = file.read()
filedata = filedata.replace('djecommerce', new_project_name)
with open(f, 'w') as file:
file.write(filedata)
os.rename(folder_to_rename, new_project_name)
self.stdout.write(self.style.SUCCESS(
'Project has been renamed to %s' % new_project_name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment