Answer the question
In order to leave comments, you need to log in
Is it possible to upload a txt file that was created in a function?
I'm new to Django I have
this question
I'm submitting data via an html form
It has fields: name and file itself The file
is an archive
I wrote a function that works with this archive, reads its contents and overwrites it in a new txt file. This txt file is saved in the project folder
The question is: is it possible to do something so that this txt file, which is created by the function, is loaded into the Django database itself?
Under this file, I created a model with a FileField field type, but I don’t know how to enter information. Help
Answer the question
In order to leave comments, you need to log in
If it's reading the content, I'm assuming it's doing it with a loop (line by line), and I'm also assuming you have a Text model with a text field. You can do something like this if you want to record the entire text:
text_list = []
for line in some_file:
text_list.append(line)
new_text = Text.objects.create(text=text_list)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question