from django.http import HttpResponse
from wagtail.wagtailimages.models import Filter, Image


def get_full_image_url(request, image_id):
    image = Image.objects.get(id=image_id)
    if image:
        filter, _ = Filter.objects.get_or_create(spec='original')
        orig_rendition = image.get_rendition(filter)
        return HttpResponse(orig_rendition.img_tag())
    else:
        return HttpResponse('')

from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from wagtail.wagtailimages.models import Filter, get_iamge_model

Image = get_iamge_model()


def get_full_image_url(request, image_id):
    image = get_object_or_404(Image, id=image_id)
    if image:
        filter, _ = Filter.objects.get_or_create(spec='original')
        orig_rendition = image.get_rendition(filter)
        return HttpResponse(orig_rendition.img_tag())
    else:
        return HttpResponse('')

Allow for custom image models, 404 on image not found intead of error
Allow for custom image models, 404 on image not found intead of error

  from django.http import HttpResponse
+ from django.shortcuts import get_object_or_404
- from wagtail.wagtailimages.models import Filter, Image
+ from wagtail.wagtailimages.models import Filter, get_iamge_model
+ 
+ Image = get_iamge_model()
  
  
  def get_full_image_url(request, image_id):
-     image = Image.objects.get(id=image_id)
+     image = get_object_or_404(Image, id=image_id)
      if image:
          filter, _ = Filter.objects.get_or_create(spec='original')
          orig_rendition = image.get_rendition(filter)
          return HttpResponse(orig_rendition.img_tag())
      else:
          return HttpResponse('')
  
Allow for custom image models, 404 on image not found intead of error
## Code Before:
from django.http import HttpResponse
from wagtail.wagtailimages.models import Filter, Image


def get_full_image_url(request, image_id):
    image = Image.objects.get(id=image_id)
    if image:
        filter, _ = Filter.objects.get_or_create(spec='original')
        orig_rendition = image.get_rendition(filter)
        return HttpResponse(orig_rendition.img_tag())
    else:
        return HttpResponse('')

## Instruction:
Allow for custom image models, 404 on image not found intead of error
## Code After:
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from wagtail.wagtailimages.models import Filter, get_iamge_model

Image = get_iamge_model()


def get_full_image_url(request, image_id):
    image = get_object_or_404(Image, id=image_id)
    if image:
        filter, _ = Filter.objects.get_or_create(spec='original')
        orig_rendition = image.get_rendition(filter)
        return HttpResponse(orig_rendition.img_tag())
    else:
        return HttpResponse('')
