[Fixed]-Wagail one page with different content

1👍

Page objects (and any classes that inherit from Page) have a get_context method that can be used to add context pre-rendering of your templates.

from django.shortcuts import get_object_or_404

class PhotoPage(Page):
    # your model definition ...
    def get_context(self, request):
        context = super(PhotoPage, self).get_context(request)
        photo_pk = request.GET.get('id',None)
        photo = get_object_or_404(YourPhotoModel,pk=photo_pk) # if no matching photo, return 404. You can do whatever you like instead :)
        context['photo'] = photo
        return context

Now in your photo template you can access your Photo model instance directly…

{{ photo.some_attribute }}
{{ photo.some_other_attribute }}

Leave a comment