Do I return it with httpResponse? Is there another way to call my image that's in a static folder?(in python file directly: usual process I follow is to save images in a static file. Then call that image in html file) but I'm trying to return an image in python file. Sorry if this isn't clear. I'll demonstrate with this code.
def extract(url):
g = Goose()
article = g.extract(url=url)
if article.top_image is None:
return "none"
else:
if article.top_image.src is None:
return "none"
else:
resposne = {'image':article.top_image.src}
return article.top_image.src
Here instead of returning "none" I want to insert an image.
In views.py
def form_valid(self, form):
self.object = form.save(commit=False)
# any manual settings go here
self.object.moderator = self.request.user
self.object.image = extract(self.object.url)
self.object.save()
return HttpResponseRedirect(reverse('post', args=[self.object.slug]))
Then in html file, I use post.image.
Again, I'm just trying to return some random image that's in my static file to be displayed instead of "none". Not sure how to do this...thanks in advance
Edit: What I'm trying to do is this. in first block of code, I'm returing "none" right/instead of none I want to return an image I saved on my static folder. ex) image = "some code" and that image to be rendered in views.py and use post.image in html file/ right now if I do post.image it shows broken image because I'm returning "none"
class PostCreateView(CreateView):
model = Post
form_class = PostForm
template_name = 'main/add_post.html'
def form_valid(self, form):
self.object = form.save(commit=False)
# any manual settings go here
self.object.moderator = self.request.user
self.object.image = extract(self.object.url)
self.object.save()
return HttpResponseRedirect(reverse('post', args=[self.object.slug]))
@method_decorator(login_required)
def dispatch(self, request, *args, **kwargs):
return super(PostCreateView, self).dispatch(request, *args, **kwargs)