我正在尝试开始这个教程...我必须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))
2条答案
按热度按时间bogh5gae1#
我有同样的错误。在视频教程有点不同的代码
变化
到
加
变化
到
并调用
bmp9r5qi2#
您使用的Django版本可能比视频中的版本更新。在这种情况下,您需要输入(使用视频中的值):
rename命令现在需要旧文件夹名和新文件夹名。