1👍
✅
Django can handle the caching of views and templates for you. There doesn’t seem to be a very good reason to render static files for this.
You can use a custom view to check if the models are publicly available:
def view_public_object(request, object_id):
object = get_object_or_404(Object, id=object_id)
if object.is_published():
return render_to_response('template.html', {'object': object})
return Http404
If you’re listing out all the objects that can be accessed, you can update the manager of the object to list only publicly available instances with this queryset:
Object.objects.filter(is_published=True)
Source:stackexchange.com