In django how to return the object without saving in the database just ceate at runtime and give in response
from django.shortcuts import render
import requests
from bs4 import BeautifulSoup
from home.models import MetaData,project
def extractURL(request):
if request.method == "POST":
# Making a GET request
url = request.POST.get('url')
varProj = project.objects.get(id=1)
r = requests.get(url)
soup = BeautifulSoup(r.content,"html.parser")
print(soup.find_all('loc')[0].text)
res = soup.find_all('loc')
resArr = []
for x in res:
resArr.append(x.text)
for y in resArr:
getPage = requests.get(y)
tempSoup = BeautifulSoup(getPage.content,"html.parser")
print(tempSoup.find_all('title')[0].text)
print(tempSoup.find_all('meta',attrs={"name":"description"}))
x = MetaData.objects.create(title=tempSoup.find_all('title')[0].text,description=tempSoup.find_all('meta',attrs={"name":"description"}),url=y,project=varProj)
x.save()
# print(tempSoup.find_all('meta',attrs={"name":"keywords"}))
# resObjArrary.append(MetaData(tempSoup.find_all('title')[0].text,tempSoup.find_all('meta',attrs={"name":"description"}),y))
# resObjArrary[count] = MetaData(tempSoup.find_all('title')[0].text,tempSoup.find_all('meta',attrs={"name":"description"}),y)
# print(tempSoup.find_all('description')[0].text)
# soup = BeautifulSoup(r)
resObj = MetaData.objects.filter(project=varProj)
context = {
"res":res,
"resObj":resObj
}
# print(soup)
return render(request,"index.html",context)
With this peice of code i am getting a sitemap url and then iteration over that after the iteration i am creating metaDataa of the page saving in my database then return which i can iterate in my frontend now i want is three any way by which i can send the object with out saving send the object just at the run time