我的数据库中有数据(名为File1)。我想访问数据库的元素,我想将这些数据用作字符串。此外,我想将该字符串写入文件。但是当我使用File1.objects.all()时,我得到一个查询集。我希望Query中的元素设置为字符串。 views.py
def getfile1(a):
data=File1.objects.all()
return data
example1.py
from django.conf.urls import include,url
import os
os.environ['DJANGO_SETTINGS_MODULE']='websitepc.settings'
import django
django.setup()
from plagiarism.views import getfile1
dbf1=getfile1(2)
print(dbf1)
exf1=dbf1.get()
print(exf1)
open("examplefile1.py", "w").close()
file = open("examplefile1.py", "w")
file.write(exf1)
我的数据库包含文字(通过表格输入,for further understanding of how I entered data into database click here)
我得到的输出是
C:\Users\DELL\PycharmProjects\sum\venv\Scripts\python.exe C:/Users/DELL/Desktop/websitepc/plagiarism/example1.py
Traceback (most recent call last):
File "C:/Users/DELL/Desktop/websitepc/plagiarism/example1.py", line 16, in <module>
file.write(exf1)
TypeError: write() argument must be str, not File1
<QuerySet [<File1: abcd>]>
abcd
Process finished with exit code 1