当我尝试将django中上传的csv文件的第一列转换为列表时,我遇到了问题.最初,我的代码是这样的,没有使用django:
with open("export.csv") as f:
my_list = [row["BASE_NAME"] for row in DictReader(f)]
Run Code Online (Sandbox Code Playgroud)
但是在开发用户界面时django,我没有my_list上面提到的要求,我做错了什么?我尝试了许多方法,你可以在评论代码中看到:
这是我的 view.py:
def handle_csv_data(csv_file):
logging.warning('Watch out!') # will print a message to the console
#print(csv_file)
# with open(csv_file) as f:
# my_list = [row["BASE_NAME"] for row in DictReader(f)]
users = []
for row in csv_file:
users.append(row)
return (users)
def home(request):
if request.method=="POST":
img = UploadForm(request.POST, request.FILES)
if img.is_valid():
logging.warning('Watch out!') # will print a message to the console
# paramFile = request.FILES['pic']
paramFile …Run Code Online (Sandbox Code Playgroud)