错误:需要以下参数:新的(如何使用Django和Python构建电子商务网站)
我正在尝试启动本教程...我必须在安装一些软件包并调整要求。现在,我正在尝试重命名该项目,并且遇到了一个错误:
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))
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))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有同样的错误。
在视频教程中,进行了一些不同的代码
更改
以
添加
更改
调用
并
I had the same error.
In the video-tutorial a little different code
change
to
add
change
to
and call
您可能使用的是Django的最新版本,而不是视频。在这种情况下,您需要键入(在视频中使用值):
重命名命令现在需要旧的foldername和新名称。
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):
The rename command now requires both the old foldername and the new name for it.