我正在从事的django项目涉及上载文件夹的tar并分析其内容。当我要求它打印该tar文件的内容时,它不在文件夹名称末尾打印'/
'。
查看forms.py
中与该类相对应的代码。 (上传的tar包含作业,因此该类名为AssignmentImportForm
)
class AssignmentImportForm(forms.Form):
assignment_archive = forms.FileField(
required=True,
label="Assignment Archive",
help_text="Please upload the assignment archive that follows the structure given in the above sample archive. Accepted archives are tar, tar.gz."
)
def __init__(self, *args, **kwargs):
kwargs['error_class']=DivErrorList
super(AssignmentImportForm, self).__init__(*args, **kwargs)
def check_bulk_add(self, data):
"""
Checks whether the uploaded folder for bulk files of assignment is in specified format
Args:
data: the archive corresponding to the folder to be uploaded
Returns: true or false depending on whether the uploaded folder is in specified format
"""
#<-----------------------------------------------------
with Archive(fileobj=data['assignment_archive']) as archive111:
x = archive111.getall_members()
print(x) ###########################################
#HERE, I'VE ASKED TO PRINT ALL FILES AND FOLDERS INSIDE UPLOADED TAR
#<-----------------------------------------------------
if 'assignment_archive' in self.changed_data and data.get('assignment_archive', ''):
err_message = bulk_import_check(data, self.this_course)
if err_message != '':
raise forms.ValidationError(err_message)
else:
if not hasattr(self, 'assignment_archive'):
return
我已要求它打印我上传的tar文件的内容。 tar文件的内容如下:
- assignment.tar.gz
|
+---Addition
|
+---Configuration
|
\----Configuration.txt
但是它没有在文件夹名称的末尾打印'/
'。但是对于一个tar文件,它正在打印'/
'。对于剩余的tar文件,其打印如下:
有人可以解释为什么吗?