Read file gracefully in django

linkaiyi
Follow

open and read file into a variable in django

    def get(self, request, *args, **kwargs):
        if request.user.is_superuser:
            report_path = os.path.join(settings.BASE_DIR, 'access_log', 'report.html')
            with open(report_path, 'r') as f:
                html = f.read()
            return HttpResponse(html)
        else:
            raise Http404(_("Benutzer ist nicht berechtigt!"))

return static html page in django

as the example shown before, return static html as string to HttpResponse.

Object has 0 attachments

Was this article helpful?

This article is viewed 9 times!

Recent Viewed Articles

Related Articles

0 Comments

Leave a Comment

Support