Here are the steps that worked for me: step 0: In your command line, go to your project directory (where manage.py exists) Step 1: pip install whitenoise make sure this library is added to the requirements.txt ( pip freeze > requirements.txt) Step 2: go to your settings.py folder and locate MIDDLEWARE. add 'whitenoise.middleware.WhiteNoiseMiddleware' , Step 3: in the same settings.py add STATIC_ROOT = os.path.join(BASE_DIR, 'static') for my case it was just above django_heroku.settings(locals()) Step 4: now go to your wsgi.py file in the same directory as settings.py type the following at the top from whitenoise import WhiteNoise also at the bottom you will use the import so add application = WhiteNoise(application) Step 5: now change DEBUG = False and go back to the command prompt in the project directory Step 6: type python manage.py collectstatic after this a new folder will appear in the root directory of yo...
Views.py from django.shortcuts import render from io import BytesIO from django.http import HttpResponse from django.template.loader import get_template from xhtml2pdf import pisa from django.views import generic import pandas as pd # Create your views here. # defining the function to convert an HTML file to a PDF file def html_to_pdf ( template_src , context_dict ={}): template = get_template(template_src) html = template.render(context_dict) result = BytesIO() pdf = pisa.pisaDocument(BytesIO(html.encode( "ISO-8859-1" )), result) if not pdf.err: return HttpResponse(result.getvalue(), content_type = 'application/pdf' ) return None class GeneratePdf ( generic . View ): def get ( self , request , * args , ** kwargs ): ...
Download the package unzip it if it is zipped cd into the directory containing setup.py If there are any installation instructions contained in documentation, read and follow the instructions OTHERWISE type in python setup.py install
Comments
Post a Comment