I am trying to start this tutorial... I had to pip install a few packages and adjust requirements.txt a bit. Now, I'm trying to rename the project and I am getting an error:
manage.py rename: error: the following arguments are required: new
https://www.youtube.com/watch?v=YZvRrldjf1Y&t=1485s&ab_channel=freeCodeCamp.org
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('current', type=str, nargs=' ',
help='The current Django project folder name')
parser.add_argument('new', type=str, nargs=' ',
help='The new Django project name')
def handle(self, *args, **kwargs):
current_project_name = kwargs['current'][0]
new_project_name = kwargs['new'][0]
# logic for renaming the files
files_to_rename = [f'{current_project_name}/settings/base.py',
f'{current_project_name}/wsgi.py', 'manage.py']
for f in files_to_rename:
with open(f, 'r') as file:
filedata = file.read()
filedata = filedata.replace(current_project_name, new_project_name)
with open(f, 'w') as file:
file.write(filedata)
os.rename(current_project_name, new_project_name)
self.stdout.write(self.style.SUCCESS(
'Project has been renamed to %s' % new_project_name))
CodePudding user response:
You may be using a more recent version of Django than the video. In this case you'd want to type (to use the values in the video):
python manage.py rename demo djecommerce
The rename command now requires both the old foldername and the new name for it.