django.template.loader.render_to_string - python examples

Here are the examples of the python api django.template.loader.render_to_string taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

145 Examples 7

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
def download_cv_pdf(request, pk):
    cv = get_object_or_404(CurriculumVitae, pk=pk)

    response = HttpResponse(content_type="application/pdf")
    response["Content-Disposition"] = \
        f"attachment; filename='{slugify(cv, True)}.pdf'"

    html = render_to_string("cv/cv_pdf.html", {"cv": cv})
    status = pisa.CreatePDF(html,
                            dest=response,
                            link_callback=link_callback)

    if status.err:
        return HttpResponse("The PDF could not be generated")

    return response

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
def download_cv_pdf(request, pk):
    cv = get_object_or_404(CurriculumVitae, pk=pk)

    response = HttpResponse(content_type="application/pdf")
    response["Content-Disposition"] = \
        f"attachment; filename='{slugify(cv, True)}.pdf'"

    html = render_to_string("cv/cv_pdf.html", {"cv": cv})
    status = pisa.CreatePDF(html,
                            dest=response,
                            link_callback=link_callback)

    if status.err:
        return HttpResponse("The PDF could not be generated")

    return response

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
@csrf_protect
def delete_quote_picture(request, filename):
    if request.method == "DELETE" \
            and request.is_ajax() \
            and filename:
        try:
            upload_to = _upload_to(request, filename)
            upload_storage.delete(upload_to)
        except FileNotFoundError:
            past
    json = render_to_string("quotes/upload.json", {"files": []})
    return HttpResponse(json,
                        content_type="application/json",
                        status=200)

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
@csrf_protect
def delete_quote_picture(request, filename):
    if request.method == "DELETE" \
            and request.is_ajax() \
            and filename:
        try:
            upload_to = _upload_to(request, filename)
            upload_storage.delete(upload_to)
        except FileNotFoundError:
            past
    json = render_to_string("quotes/upload.json", {"files": []})
    return HttpResponse(json,
                        content_type="application/json",
                        status=200)

3 View Complete Implementation : likes_tags.py
Copyright MIT License
Author : PacktPublishing
    def render(self, context):
        liked_object = self.var.resolve(context)
        ct = ContentType.objects.get_for_model(liked_object)
        user = context["request"].user

        if not user.is_authenticated:
            return ""

        context.push(object=liked_object,
                     content_type_id=ct.pk)
        #              is_liked_by_user=liked_by(liked_object,
        #                                        user),
        #              count=liked_count(liked_object))
        output = render_to_string("likes/includes/widget.html",
                                  context.flatten())
        context.pop()
        return output

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
def download_cv_pdf(request, pk):
    cv = get_object_or_404(CurriculumVitae, pk=pk)

    response = HttpResponse(content_type="application/pdf")
    response["Content-Disposition"] = \
        f"attachment; filename='{slugify(cv, True)}.pdf'"

    html = render_to_string("cv/cv_pdf.html", {"cv": cv})
    status = pisa.CreatePDF(html,
                            dest=response,
                            link_callback=link_callback)

    if status.err:
        return HttpResponse("The PDF could not be generated")

    return response

3 View Complete Implementation : likes_tags.py
Copyright MIT License
Author : PacktPublishing
    def render(self, context):
        liked_object = self.var.resolve(context)
        ct = ContentType.objects.get_for_model(liked_object)
        user = context["request"].user

        if not user.is_authenticated:
            return ""

        context.push(object=liked_object,
                     content_type_id=ct.pk)
        #              is_liked_by_user=liked_by(liked_object,
        #                                        user),
        #              count=liked_count(liked_object))
        output = render_to_string("likes/includes/widget.html",
                                  context.flatten())
        context.pop()
        return output

3 View Complete Implementation : likes_tags.py
Copyright MIT License
Author : PacktPublishing
    def render(self, context):
        liked_object = self.var.resolve(context)
        ct = ContentType.objects.get_for_model(liked_object)
        user = context["request"].user

        if not user.is_authenticated:
            return ""

        context.push(object=liked_object,
                     content_type_id=ct.pk)
        #              is_liked_by_user=liked_by(liked_object,
        #                                        user),
        #              count=liked_count(liked_object))
        output = render_to_string("likes/includes/widget.html",
                                  context.flatten())
        context.pop()
        return output

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
def download_cv_pdf(request, pk):
    cv = get_object_or_404(CurriculumVitae, pk=pk)

    response = HttpResponse(content_type="application/pdf")
    response["Content-Disposition"] = \
        f"attachment; filename='{slugify(cv, True)}.pdf'"

    html = render_to_string("cv/cv_pdf.html", {"cv": cv})
    status = pisa.CreatePDF(html,
                            dest=response,
                            link_callback=link_callback)

    if status.err:
        return HttpResponse("The PDF could not be generated")

    return response

3 View Complete Implementation : admin.py
Copyright MIT License
Author : PacktPublishing
    def first_photo(self, obj):
        project_photos = obj.productphoto_set.all()[:1]
        if project_photos.count() > 0:
            photo_preview = render_to_string(
                "products/includes/photo-preview.html",
                {
                    "photo": project_photos[0],
                    "size": "100",
                    "product": obj,
                    "target": "preview",
                })
            return mark_safe(photo_preview)
        return ""

3 View Complete Implementation : admin.py
Copyright MIT License
Author : PacktPublishing
    def first_photo(self, obj):
        project_photos = obj.productphoto_set.all()[:1]
        if project_photos.count() > 0:
            photo_preview = render_to_string(
                "products/includes/photo-preview.html",
                {
                    "photo": project_photos[0],
                    "size": "100",
                    "product": obj,
                    "target": "preview",
                })
            return mark_safe(photo_preview)
        return ""

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
@csrf_protect
def delete_quote_picture(request, filename):
    if request.method == "DELETE" \
            and request.is_ajax() \
            and filename:
        try:
            upload_to = _upload_to(request, filename)
            upload_storage.delete(upload_to)
        except FileNotFoundError:
            past
    json = render_to_string("quotes/upload.json", {"files": []})
    return HttpResponse(json,
                        content_type="application/json",
                        status=200)

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
def download_cv_pdf(request, pk):
    cv = get_object_or_404(CurriculumVitae, pk=pk)

    response = HttpResponse(content_type="application/pdf")
    response["Content-Disposition"] = \
        f"attachment; filename='{slugify(cv, True)}.pdf'"

    html = render_to_string("cv/cv_pdf.html", {"cv": cv})
    status = pisa.CreatePDF(html,
                            dest=response,
                            link_callback=link_callback)

    if status.err:
        return HttpResponse("The PDF could not be generated")

    return response

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
def download_cv_pdf(request, pk):
    cv = get_object_or_404(CurriculumVitae, pk=pk)

    response = HttpResponse(content_type="application/pdf")
    response["Content-Disposition"] = \
        f"attachment; filename='{slugify(cv, True)}.pdf'"

    html = render_to_string("cv/cv_pdf.html", {"cv": cv})
    status = pisa.CreatePDF(html,
                            dest=response,
                            link_callback=link_callback)

    if status.err:
        return HttpResponse("The PDF could not be generated")

    return response

3 View Complete Implementation : likes_tags.py
Copyright MIT License
Author : PacktPublishing
    def render(self, context):
        liked_object = self.var.resolve(context)
        ct = ContentType.objects.get_for_model(liked_object)
        user = context["request"].user

        if not user.is_authenticated:
            return ""

        context.push(object=liked_object,
                     content_type_id=ct.pk)
        #              is_liked_by_user=liked_by(liked_object,
        #                                        user),
        #              count=liked_count(liked_object))
        output = render_to_string("likes/includes/widget.html",
                                  context.flatten())
        context.pop()
        return output

3 View Complete Implementation : admin.py
Copyright MIT License
Author : PacktPublishing
    def first_photo(self, obj):
        project_photos = obj.productphoto_set.all()[:1]
        if project_photos.count() > 0:
            photo_preview = render_to_string(
                "products/includes/photo-preview.html",
                {
                    "photo": project_photos[0],
                    "size": "100",
                    "product": obj,
                    "target": "preview",
                })
            return mark_safe(photo_preview)
        return ""

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
@csrf_protect
def delete_quote_picture(request, filename):
    if request.method == "DELETE" \
            and request.is_ajax() \
            and filename:
        try:
            upload_to = _upload_to(request, filename)
            upload_storage.delete(upload_to)
        except FileNotFoundError:
            past
    json = render_to_string("quotes/upload.json", {"files": []})
    return HttpResponse(json,
                        content_type="application/json",
                        status=200)

3 View Complete Implementation : likes_tags.py
Copyright MIT License
Author : PacktPublishing
    def render(self, context):
        liked_object = self.var.resolve(context)
        ct = ContentType.objects.get_for_model(liked_object)
        user = context["request"].user

        if not user.is_authenticated:
            return ""

        context.push(object=liked_object,
                     content_type_id=ct.pk)
        #              is_liked_by_user=liked_by(liked_object,
        #                                        user),
        #              count=liked_count(liked_object))
        output = render_to_string("likes/includes/widget.html",
                                  context.flatten())
        context.pop()
        return output

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
@csrf_protect
def delete_quote_picture(request, filename):
    if request.method == "DELETE" \
            and request.is_ajax() \
            and filename:
        try:
            upload_to = _upload_to(request, filename)
            upload_storage.delete(upload_to)
        except FileNotFoundError:
            past
    json = render_to_string("quotes/upload.json", {"files": []})
    return HttpResponse(json,
                        content_type="application/json",
                        status=200)

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
def download_cv_pdf(request, pk):
    cv = get_object_or_404(CurriculumVitae, pk=pk)

    response = HttpResponse(content_type="application/pdf")
    response["Content-Disposition"] = \
        f"attachment; filename='{slugify(cv, True)}.pdf'"

    html = render_to_string("cv/cv_pdf.html", {"cv": cv})
    status = pisa.CreatePDF(html,
                            dest=response,
                            link_callback=link_callback)

    if status.err:
        return HttpResponse("The PDF could not be generated")

    return response

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
def download_cv_pdf(request, pk):
    cv = get_object_or_404(CurriculumVitae, pk=pk)

    response = HttpResponse(content_type="application/pdf")
    response["Content-Disposition"] = \
        f"attachment; filename='{slugify(cv, True)}.pdf'"

    html = render_to_string("cv/cv_pdf.html", {"cv": cv})
    status = pisa.CreatePDF(html,
                            dest=response,
                            link_callback=link_callback)

    if status.err:
        return HttpResponse("The PDF could not be generated")

    return response

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
@csrf_protect
def delete_quote_picture(request, filename):
    if request.method == "DELETE" \
            and request.is_ajax() \
            and filename:
        try:
            upload_to = _upload_to(request, filename)
            upload_storage.delete(upload_to)
        except FileNotFoundError:
            past
    json = render_to_string("quotes/upload.json", {"files": []})
    return HttpResponse(json,
                        content_type="application/json",
                        status=200)

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
@csrf_protect
def delete_quote_picture(request, filename):
    if request.method == "DELETE" \
            and request.is_ajax() \
            and filename:
        try:
            upload_to = _upload_to(request, filename)
            upload_storage.delete(upload_to)
        except FileNotFoundError:
            past
    json = render_to_string("quotes/upload.json", {"files": []})
    return HttpResponse(json,
                        content_type="application/json",
                        status=200)

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
def download_cv_pdf(request, pk):
    cv = get_object_or_404(CurriculumVitae, pk=pk)

    response = HttpResponse(content_type="application/pdf")
    response["Content-Disposition"] = \
        f"attachment; filename='{slugify(cv, True)}.pdf'"

    html = render_to_string("cv/cv_pdf.html", {"cv": cv})
    status = pisa.CreatePDF(html,
                            dest=response,
                            link_callback=link_callback)

    if status.err:
        return HttpResponse("The PDF could not be generated")

    return response

3 View Complete Implementation : admin.py
Copyright MIT License
Author : PacktPublishing
    def first_photo(self, obj):
        project_photos = obj.productphoto_set.all()[:1]
        if project_photos.count() > 0:
            photo_preview = render_to_string(
                "products/includes/photo-preview.html",
                {
                    "photo": project_photos[0],
                    "size": "100",
                    "product": obj,
                    "target": "preview",
                })
            return mark_safe(photo_preview)
        return ""

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
@csrf_protect
def delete_quote_picture(request, filename):
    if request.method == "DELETE" \
            and request.is_ajax() \
            and filename:
        try:
            upload_to = _upload_to(request, filename)
            upload_storage.delete(upload_to)
        except FileNotFoundError:
            past
    json = render_to_string("quotes/upload.json", {"files": []})
    return HttpResponse(json,
                        content_type="application/json",
                        status=200)

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
def download_cv_pdf(request, pk):
    cv = get_object_or_404(CurriculumVitae, pk=pk)

    response = HttpResponse(content_type="application/pdf")
    response["Content-Disposition"] = \
        f"attachment; filename='{slugify(cv, True)}.pdf'"

    html = render_to_string("cv/cv_pdf.html", {"cv": cv})
    status = pisa.CreatePDF(html,
                            dest=response,
                            link_callback=link_callback)

    if status.err:
        return HttpResponse("The PDF could not be generated")

    return response

3 View Complete Implementation : admin.py
Copyright MIT License
Author : PacktPublishing
    def first_photo(self, obj):
        project_photos = obj.productphoto_set.all()[:1]
        if project_photos.count() > 0:
            photo_preview = render_to_string(
                "products/includes/photo-preview.html",
                {
                    "photo": project_photos[0],
                    "size": "100",
                    "product": obj,
                    "target": "preview",
                })
            return mark_safe(photo_preview)
        return ""

3 View Complete Implementation : admin.py
Copyright MIT License
Author : PacktPublishing
    def first_photo(self, obj):
        project_photos = obj.productphoto_set.all()[:1]
        if project_photos.count() > 0:
            photo_preview = render_to_string(
                "products/includes/photo-preview.html",
                {
                    "photo": project_photos[0],
                    "size": "100",
                    "product": obj,
                    "target": "preview",
                })
            return mark_safe(photo_preview)
        return ""

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
def download_cv_pdf(request, pk):
    cv = get_object_or_404(CurriculumVitae, pk=pk)

    response = HttpResponse(content_type="application/pdf")
    response["Content-Disposition"] = \
        f"attachment; filename='{slugify(cv, True)}.pdf'"

    html = render_to_string("cv/cv_pdf.html", {"cv": cv})
    status = pisa.CreatePDF(html,
                            dest=response,
                            link_callback=link_callback)

    if status.err:
        return HttpResponse("The PDF could not be generated")

    return response

3 View Complete Implementation : likes_tags.py
Copyright MIT License
Author : PacktPublishing
    def render(self, context):
        liked_object = self.var.resolve(context)
        ct = ContentType.objects.get_for_model(liked_object)
        user = context["request"].user

        if not user.is_authenticated:
            return ""

        context.push(object=liked_object,
                     content_type_id=ct.pk)
        #              is_liked_by_user=liked_by(liked_object,
        #                                        user),
        #              count=liked_count(liked_object))
        output = render_to_string("likes/includes/widget.html",
                                  context.flatten())
        context.pop()
        return output

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
@csrf_protect
def delete_quote_picture(request, filename):
    if request.method == "DELETE" \
            and request.is_ajax() \
            and filename:
        try:
            upload_to = _upload_to(request, filename)
            upload_storage.delete(upload_to)
        except FileNotFoundError:
            past
    json = render_to_string("quotes/upload.json", {"files": []})
    return HttpResponse(json,
                        content_type="application/json",
                        status=200)

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
@csrf_protect
def delete_quote_picture(request, filename):
    if request.method == "DELETE" \
            and request.is_ajax() \
            and filename:
        try:
            upload_to = _upload_to(request, filename)
            upload_storage.delete(upload_to)
        except FileNotFoundError:
            past
    json = render_to_string("quotes/upload.json", {"files": []})
    return HttpResponse(json,
                        content_type="application/json",
                        status=200)

3 View Complete Implementation : likes_tags.py
Copyright MIT License
Author : PacktPublishing
    def render(self, context):
        liked_object = self.var.resolve(context)
        ct = ContentType.objects.get_for_model(liked_object)
        user = context["request"].user

        if not user.is_authenticated:
            return ""

        context.push(object=liked_object,
                     content_type_id=ct.pk)
        #              is_liked_by_user=liked_by(liked_object,
        #                                        user),
        #              count=liked_count(liked_object))
        output = render_to_string("likes/includes/widget.html",
                                  context.flatten())
        context.pop()
        return output

3 View Complete Implementation : admin.py
Copyright MIT License
Author : PacktPublishing
    def first_photo(self, obj):
        project_photos = obj.productphoto_set.all()[:1]
        if project_photos.count() > 0:
            photo_preview = render_to_string(
                "products/includes/photo-preview.html",
                {
                    "photo": project_photos[0],
                    "size": "100",
                    "product": obj,
                    "target": "preview",
                })
            return mark_safe(photo_preview)
        return ""

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
@csrf_protect
def delete_quote_picture(request, filename):
    if request.method == "DELETE" \
            and request.is_ajax() \
            and filename:
        try:
            upload_to = _upload_to(request, filename)
            upload_storage.delete(upload_to)
        except FileNotFoundError:
            past
    json = render_to_string("quotes/upload.json", {"files": []})
    return HttpResponse(json,
                        content_type="application/json",
                        status=200)

3 View Complete Implementation : likes_tags.py
Copyright MIT License
Author : PacktPublishing
    def render(self, context):
        liked_object = self.var.resolve(context)
        ct = ContentType.objects.get_for_model(liked_object)
        user = context["request"].user

        if not user.is_authenticated:
            return ""

        context.push(object=liked_object,
                     content_type_id=ct.pk)
        #              is_liked_by_user=liked_by(liked_object,
        #                                        user),
        #              count=liked_count(liked_object))
        output = render_to_string("likes/includes/widget.html",
                                  context.flatten())
        context.pop()
        return output

3 View Complete Implementation : likes_tags.py
Copyright MIT License
Author : PacktPublishing
    def render(self, context):
        liked_object = self.var.resolve(context)
        ct = ContentType.objects.get_for_model(liked_object)
        user = context["request"].user

        if not user.is_authenticated:
            return ""

        context.push(object=liked_object,
                     content_type_id=ct.pk)
        #              is_liked_by_user=liked_by(liked_object,
        #                                        user),
        #              count=liked_count(liked_object))
        output = render_to_string("likes/includes/widget.html",
                                  context.flatten())
        context.pop()
        return output

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
def download_cv_pdf(request, pk):
    cv = get_object_or_404(CurriculumVitae, pk=pk)

    response = HttpResponse(content_type="application/pdf")
    response["Content-Disposition"] = \
        f"attachment; filename='{slugify(cv, True)}.pdf'"

    html = render_to_string("cv/cv_pdf.html", {"cv": cv})
    status = pisa.CreatePDF(html,
                            dest=response,
                            link_callback=link_callback)

    if status.err:
        return HttpResponse("The PDF could not be generated")

    return response

3 View Complete Implementation : likes_tags.py
Copyright MIT License
Author : PacktPublishing
    def render(self, context):
        liked_object = self.var.resolve(context)
        ct = ContentType.objects.get_for_model(liked_object)
        user = context["request"].user

        if not user.is_authenticated:
            return ""

        context.push(object=liked_object,
                     content_type_id=ct.pk)
        #              is_liked_by_user=liked_by(liked_object,
        #                                        user),
        #              count=liked_count(liked_object))
        output = render_to_string("likes/includes/widget.html",
                                  context.flatten())
        context.pop()
        return output

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
@csrf_protect
def delete_quote_picture(request, filename):
    if request.method == "DELETE" \
            and request.is_ajax() \
            and filename:
        try:
            upload_to = _upload_to(request, filename)
            upload_storage.delete(upload_to)
        except FileNotFoundError:
            past
    json = render_to_string("quotes/upload.json", {"files": []})
    return HttpResponse(json,
                        content_type="application/json",
                        status=200)

3 View Complete Implementation : admin.py
Copyright MIT License
Author : PacktPublishing
    def first_photo(self, obj):
        project_photos = obj.productphoto_set.all()[:1]
        if project_photos.count() > 0:
            photo_preview = render_to_string(
                "products/includes/photo-preview.html",
                {
                    "photo": project_photos[0],
                    "size": "100",
                    "product": obj,
                    "target": "preview",
                })
            return mark_safe(photo_preview)
        return ""

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
def download_cv_pdf(request, pk):
    cv = get_object_or_404(CurriculumVitae, pk=pk)

    response = HttpResponse(content_type="application/pdf")
    response["Content-Disposition"] = \
        f"attachment; filename='{slugify(cv, True)}.pdf'"

    html = render_to_string("cv/cv_pdf.html", {"cv": cv})
    status = pisa.CreatePDF(html,
                            dest=response,
                            link_callback=link_callback)

    if status.err:
        return HttpResponse("The PDF could not be generated")

    return response

3 View Complete Implementation : likes_tags.py
Copyright MIT License
Author : PacktPublishing
    def render(self, context):
        liked_object = self.var.resolve(context)
        ct = ContentType.objects.get_for_model(liked_object)
        user = context["request"].user

        if not user.is_authenticated:
            return ""

        context.push(object=liked_object,
                     content_type_id=ct.pk)
        #              is_liked_by_user=liked_by(liked_object,
        #                                        user),
        #              count=liked_count(liked_object))
        output = render_to_string("likes/includes/widget.html",
                                  context.flatten())
        context.pop()
        return output

3 View Complete Implementation : admin.py
Copyright MIT License
Author : PacktPublishing
    def first_photo(self, obj):
        project_photos = obj.productphoto_set.all()[:1]
        if project_photos.count() > 0:
            photo_preview = render_to_string(
                "products/includes/photo-preview.html",
                {
                    "photo": project_photos[0],
                    "size": "100",
                    "product": obj,
                    "target": "preview",
                })
            return mark_safe(photo_preview)
        return ""

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
def download_cv_pdf(request, pk):
    cv = get_object_or_404(CurriculumVitae, pk=pk)

    response = HttpResponse(content_type="application/pdf")
    response["Content-Disposition"] = \
        f"attachment; filename='{slugify(cv, True)}.pdf'"

    html = render_to_string("cv/cv_pdf.html", {"cv": cv})
    status = pisa.CreatePDF(html,
                            dest=response,
                            link_callback=link_callback)

    if status.err:
        return HttpResponse("The PDF could not be generated")

    return response

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
def download_cv_pdf(request, pk):
    cv = get_object_or_404(CurriculumVitae, pk=pk)

    response = HttpResponse(content_type="application/pdf")
    response["Content-Disposition"] = \
        f"attachment; filename='{slugify(cv, True)}.pdf'"

    html = render_to_string("cv/cv_pdf.html", {"cv": cv})
    status = pisa.CreatePDF(html,
                            dest=response,
                            link_callback=link_callback)

    if status.err:
        return HttpResponse("The PDF could not be generated")

    return response

3 View Complete Implementation : views.py
Copyright MIT License
Author : PacktPublishing
def download_cv_pdf(request, pk):
    cv = get_object_or_404(CurriculumVitae, pk=pk)

    response = HttpResponse(content_type="application/pdf")
    response["Content-Disposition"] = \
        f"attachment; filename='{slugify(cv, True)}.pdf'"

    html = render_to_string("cv/cv_pdf.html", {"cv": cv})
    status = pisa.CreatePDF(html,
                            dest=response,
                            link_callback=link_callback)

    if status.err:
        return HttpResponse("The PDF could not be generated")

    return response

3 View Complete Implementation : admin.py
Copyright MIT License
Author : PacktPublishing
    def first_photo(self, obj):
        project_photos = obj.productphoto_set.all()[:1]
        if project_photos.count() > 0:
            photo_preview = render_to_string(
                "products/includes/photo-preview.html",
                {
                    "photo": project_photos[0],
                    "size": "100",
                    "product": obj,
                    "target": "preview",
                })
            return mark_safe(photo_preview)
        return ""

3 View Complete Implementation : likes_tags.py
Copyright MIT License
Author : PacktPublishing
    def render(self, context):
        liked_object = self.var.resolve(context)
        ct = ContentType.objects.get_for_model(liked_object)
        user = context["request"].user

        if not user.is_authenticated:
            return ""

        context.push(object=liked_object,
                     content_type_id=ct.pk)
        #              is_liked_by_user=liked_by(liked_object,
        #                                        user),
        #              count=liked_count(liked_object))
        output = render_to_string("likes/includes/widget.html",
                                  context.flatten())
        context.pop()
        return output