为什么只能使用一个名字
def path(request, mypath):
mypath = request.path_info
_listdir = os.listdir(mypath) # ['folder1', 'folder2', 'folder3', 'folder4']
mess = _listdir
a = ' '
x=0
scope = vars()
for i in mess:
scope['x']+=1
a += mess[x]
a += '\n'
return HttpResponse(a)
我希望输出是这样的:
folder1 folder2 folder3 folder4
但为什么输出却是这样的:
folder1 folder1 folder1 folder1
有人能帮忙吗?
5 个回答
3
4
那个函数里面有很多不必要的代码。
def path(request):
return HttpResponse('\n'.join(os.listdir(request.path_info)))
工作完成了!
1
I hope the output is like this: folder1 folder2 folder3 folder4
这样你就能得到你想要的输出...
for i in os.listdir(mypath):
print i
你可以在循环中用 HttpResponse
返回 i
,这样应该没问题,照这样做就行。
returnString = ""
for i in os.listdir(mypath):
returnString = returnString + i + "\n"
return returnString