Reputation: 25
I'm trying to assign an id to a CSV file's name so that when I click on a link beside I can access the CSV file itself on another web page to view it.
but I keep getting this error 'QueryDict' object has no attribute 'objects'
Note: the CSV files are taken from a form and saved in a file on the PC, I'm trying to retrieve the file from the PC itself.
This is the views.py
def read_datasets(request):
file = request.POST.objects.get(id=id)
# print(file)
path = r"C:/Users/user/Desktop/Fault Detection App/Uploaded_Datasets/"
# csv_file = request.FILES['file2']
# csv_file = request.POST.get('file2')
path1, dirs, files = next(os.walk(path))
file_count = len(files)
print(file_count)
# dataframes_list_html = []
file_names = []
# file_name = csv_file.name
for i in range(file_count):
temp_df = pd.read_csv(path+files[i])
print(files[i])
# dataframes_list_html.append(temp_df.to_html(index=False))
file_names.append(files[i])
# print(dataframes_list_html)
return render(request,'blog/view_datasets.html',{'names': file_names})
def one_dataset(request):
path = r"C:/Users/user/Desktop/Fault Detection App/Uploaded_Datasets/"
path1, dirs, files = next(os.walk(path))
file_count = len(files)
print(file_count)
dataframes_list_html = []
for i in range(file_count):
temp_df = pd.read_csv(path+files[i])
print(files[i])
dataframes_list_html.append(temp_df.to_html(index=False))
return render(request, 'blog/single_dataset.html', {'dataframes':dataframes_list_html})
and the HTML File
<body>
{% for dataframe in dataframes %}
<div id="customers">
{{ dataframe|safe }}
<hr>
</div>
{% endfor %}
</body>
Upvotes: 0
Views: 35
Reputation: 3457
The request.POST
is a dictionary. So you have to remove .objects
def read_datasets(request):
file = request.POST.get("...")
...
Upvotes: 1