0
What is the data type of the variable data??
def write(request): if request.method == 'POST': data = request.POST with open('student.csv', 'a') as f: wrt = csv.writer(f) for key,value in data.items(): wrt.writerow( [key,value]) return render(request/form.html',('$tatus':Written'}) What is the data type of the variable data??
8 Respuestas
+ 1
It could be dictionary, because dictionary has a the method items, which turns the dictionary into an dict_items object which is filled with lists as [key, value] pairs.
{1: 1, 2: 4, 3: 27, 4: 64}.items()
---> dict_items([1, 1], [2, 4], [3, 27], [4, 64])
+ 3
You can just try it:
print(type(data))
+ 2
HonFu since it is part of the django-project it can't be executed by itself we have to run the django development server for this, in which the output is only in form of Html pages and when I tried to get the type in html output it is showing something like type is not subscriptable (i don't remember the error message completely)
+ 1
Seb TheS it makes sense
0
Mirielle🐶 [Inactive] so it would be like some POST object (if thing like that exists) like we have map-object etc...
0
HonFu the question would not have made here if that technique worked!
0
What did you get when you tried it?