Sunday, June 20, 2021

Re: help me plz: getting error while importing csv file into database

you have to pass the 'path' variable into open I believe that's it

Em sexta-feira, 18 de junho de 2021 às 15:22:41 UTC-3, rammano...@gmail.com escreveu:
Hi 
i am trying to import the csv file data into database 
 my views.py 
def Filter(request):
    if request.method=="POST":
        form = DataForm(request.POST, request.FILES)
        if form.is_valid():
            initial_obj = form.save(commit=False)
            data=initial_obj['data']
            path="C:\\Users\\ramma\\Downloads\\assesment.csv"
            os.chdir(path)

            with open('assesment.csv'as csvfile:
                reader = csv.DictReader(csvfile)
                for row in reader:
                    file=data(name=row['product'],)

            initial_obj.save()
            file.save()
            return redirect('/')
        else:
            return render(request,'index.html',{'form':form})
    else:
        return render(request,'index.html',{'form':form})


def search(request):
    list = data.objects.all()
    data_filter = DataFilter(request.GET, queryset=list)
    return render(request'product.html', {'filter'data_filter})

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/779d973e-ca1e-481d-a8cf-5feba8b32448n%40googlegroups.com.

No comments:

Post a Comment