错误:需要以下参数:new(如何使用Django和Python构建电子商务网站)

3gtaxfhh  于 2023-03-04  发布在  Go
关注(0)|答案(2)|浏览(143)

我正在尝试开始这个教程...我必须pip安装一些软件包,并调整requirements.txt一点。现在,我试图重命名项目,我得到了一个错误:
manage.py 需要以下参数:新的 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))
bogh5gae

bogh5gae1#

我有同样的错误。在视频教程有点不同的代码
变化

files_to_rename = [f'{current_project_name}/settings/base.py',
                           f'{current_project_name}/wsgi.py', 'manage.py']

files_to_rename = [f'demo'/settings.py', f'demo'/wsgi.py', 'manage.py']

folder_to_rename = 'demo'

变化

filedata = filedata.replace(current_project_name, new_project_name)

filedata = filedata.replace('demo', new_project_name)

并调用

python manage.py rename demo programname
bmp9r5qi

bmp9r5qi2#

您使用的Django版本可能比视频中的版本更新。在这种情况下,您需要输入(使用视频中的值):

python manage.py rename demo djecommerce

rename命令现在需要旧文件夹名和新文件夹名。

相关问题