我需要使用Python读取/下载用户提供的文件,但它给了我语法错误。尝试使用Python下载文件时出现语法错误
错误:
File "path1.py", line 6 return HttpResponse(content=test_file, content_type="text/plain") SyntaxError: 'return' outside function
我解释下面我的代码。
import os
from django.http import HttpResponse
#image_name = request.GET.get('param')
image_name = "63b6ac1bc61642f39c697585810aed17.txt"
test_file = os.path.join(os.getcwd(), image_name)
return HttpResponse(content=test_file, content_type="text/plain")
其实这里我的要求是如果我提供的文件名,需要读取/下载这个文件使用Python。
删除return语句。你只能在函数内部返回。 –