Django/WeasyPrint: PermissionError: [Errno 13] В ПК Win-10 отказано в разрешении
Я работаю над проектом Django. Я использую Django 1.11.6 с python3.6. Я создаю PDF, используя модуль weasyprint. Но я получил ошибку. Это произошло с weasyprint, когда я запускаю свой проект django localhost на ПК с Windows-10.
Я хочу сделать PDF-файл с weasyprint. Но когда я запускаю свой компьютер с Windows 10, я получаю ошибку разрешения. это файл views.py
def get_pdf_file(request, customer_id, sys_type):
sys_type = customer_id
area = "pdf"
site_credit = site_credit1
time_now = timezone.now()
customers = get_object_or_404(CustomerInfo, pk=customer_id)
due_taka_track = customers.duetaka_set.all()
if due_taka_track == None:
due_taka_track = 0
unpaid_taka = int(customers.customer_price -
customers.customer_due_taka_info)
due_taka_track = customers.duetaka_set.all()
sum_cost_taka = due_taka_track.aggregate(
sp=Sum('customer_due')).get('sp', 0)
if sum_cost_taka == None:
sum_cost_taka = 0
total_paid_taka = sum_cost_taka + customers.customer_due_taka_info
payment_status = 'complete'
payment_message = ' '
remain_taka='Full Paid '
remain_msg=''
if customers.customer_due_taka_info < customers.customer_price:
payment_status = 'incomplete'
payment_message = 'সম্পূর্ন টাকা পরিষোধ করা হয়নি'
remain_msg='টাকা বাকী আছে'
baki_ase="পাওনা আছে "
remain_taka = customers.customer_price - customers.customer_due_taka_info
context = {'customers': customers,
'sys_type': sys_type,
'area': area,
'site_credit': site_credit,
'site_name': 'Moon Telecom',
'sys_type': sys_type,
'due_taka_track': due_taka_track,
'total_paid_taka': total_paid_taka,
'payment_message': payment_message,
'time_now': time_now,
'unpaid_taka': unpaid_taka,
'payment_message': payment_message,
'remain_taka': remain_taka,
'sum_cost_taka': sum_cost_taka,
'remain_msg': remain_msg}
from weasyprint import HTML, CSS
html_string = render_to_string('shop/pdf_invoice.html', context)
with codecs.open('out.html', 'w', 'utf-8') as f:
f.write(html_string)
#html_string = render_to_string('shop/pdf_invoice.html', context)
html = HTML(string=html_string)
result = html.write_pdf()
response = HttpResponse(content_type='application/pdf;')
response['Content-Disposition'] = 'inline; filename=invoice' + \
str(customers.id)+customers.customer_uid + customers.customer_name + '.pdf'
response['Content-Transfer-Encoding'] = 'UTF-8'
with tempfile.NamedTemporaryFile(delete=True) as output:
output.write(result)
output.flush()
output = open(output.name, 'rb')
response.write(output.read())
return response
это трассировка
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/shop/1/report/pdf/
Django Version: 1.11.7
Python Version: 3.6.3
Installed Applications:
['shop.apps.ShopConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "C:\Program Files (x86)\lib\site-packages\django\core\handlers\exception.py" in inner
41. response = get_response(request)
File "C:\Program Files (x86)\lib\site-packages\django\core\handlers\base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)
File "C:\Program Files (x86)\lib\site-packages\django\core\handlers\base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\asad\Desktop\smartshop\django-app\shop\views.py" in get_pdf_file
906. output = open(output.name, 'rb')
Exception Type: PermissionError at /shop/1/report/pdf/
Exception Value: [Errno 13] Permission denied: 'C:\\Users\\asad\\AppData\\Local\\Temp\\tmp6j7du822'
Также я запускаю этот проект django с помощью команды cmd от имени администратора.