STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(BASE_DIR, '/static_root/')
STATICFILES_DIRS =(os.path.join(BASE_DIR,'/static/',),)
MEDIA_ROOT = os.path.join(BASE_DIR, 'static', 'media')
#STATIC_ROOT = os.path.join(BASE_DIR, 'static_root')
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) \
+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
10.06.2018 14:08 <DIR> .
10.06.2018 14:08 <DIR> ..
10.06.2018 14:08 <DIR> admin
06.06.2018 14:23 121 265 bootstrap.min.css
10.06.2018 14:08 <DIR> fonts
06.06.2018 18:42 44 footer.css
10.06.2018 14:08 <DIR> img
10.06.2018 14:08 <DIR> js
10.06.2018 14:08 <DIR> media
06.06.2018 14:23 2 544 nav.css
10.06.2018 14:08 <DIR> operator
06.06.2018 14:23 3 351 owl.carousel.min.css
06.06.2018 14:23 1 013 owl.theme.default.min.css
06.06.2018 21:01 9 121 style.css
06.06.2018 14:23 1 099 style_lk.css
7 файлов 138 437 байт
<link rel="stylesheet" href="/static/style_lk.css">
<link rel="stylesheet" href="/static/style.css">
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x04242738>
Traceback (most recent call last):
File "C:\Phyton\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Phyton\lib\site-packages\django\core\management\commands\runserver.py", line 121, in inner_run
self.check(display_num_errors=True)
File "C:\Phyton\lib\site-packages\django\core\management\base.py", line 410, in check
raise SystemCheckError(msg)
django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:
ERRORS:
?: (staticfiles.E002) The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting.
STATIC_URL = '/static/'
STATICFILES_DIRS =(os.path.join(BASE_DIR,'static/',),)
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, "static", "media")
\
+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) \
+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
2018-06-06 13:31:30,573 {C:\Phyton\lib\site-packages\xhtml2pdf\document.py:85} DEBUG - pisaDocument options:
src = <_io.BytesIO object at 0x05968540>
dest = <_io.BytesIO object at 0x05D13DB0>
path = None
link_callback = <function fetch_pdf_resources at 0x04A04DF8>
xhtml = False
context_meta = None
2018-06-06 13:31:30,613 {C:\Phyton\lib\site-packages\xhtml2pdf\context.py:810} WARNING - getFile '/static/fonts/arial.ttf' 'E:\\work\\life\\__dummy__' 'E:\\work\\life\\__dummy__'
Traceback (most recent call last):
File "C:\Phyton\lib\site-packages\xhtml2pdf\context.py", line 796, in _getFileDeprecated
nv = self.pathCallback(name, relative)
File "E:\work\life\mi_pdf\utileria.py", line 17, in fetch_pdf_resources
path = os.path.join(settings.STATIC_ROOT, uri.replace(settings.STATIC_URL, ''))
File "C:\Phyton\lib\ntpath.py", line 75, in join
path = os.fspath(path)
TypeError: expected str, bytes or os.PathLike object, not NoneType
2018-06-06 13:31:30,635 {C:\Phyton\lib\site-packages\xhtml2pdf\util.py:591} DEBUG - FileObject '', Basepath: None
2018-06-06 13:31:30,638 {C:\Phyton\lib\site-packages\xhtml2pdf\util.py:606} DEBUG - URLParts: (ParseResult(scheme='', netloc='', path='', params='', query='', fragment=''), '')
2018-06-06 13:31:30,643 {C:\Phyton\lib\site-packages\xhtml2pdf\util.py:668} DEBUG - Unrecognized scheme, assuming local file path
[06/Jun/2018 13:31:30] "GET /mi_pdf/ HTTP/1.1" 200 3663
# encoding: utf-8
from io import BytesIO
from django.http import HttpResponse
from django.template.loader import get_template
from xhtml2pdf import pisa
from reportlab.pdfbase.ttfonts import TTFont
from django.conf import settings
from life.settings import *
def fetch_pdf_resources(uri, rel):
if uri.find(settings.MEDIA_URL) != -1:
path = os.path.join(settings.MEDIA_ROOT, uri.replace(settings.MEDIA_URL, ''))
elif uri.find(settings.STATIC_URL) != -1:
path = os.path.join(settings.STATIC_ROOT, uri.replace(settings.STATIC_URL, ''))
else:
path = None
return path
def render_pdf(url_template, contexto = {}):
template = get_template(url_template)
html = template.render(contexto)
result = BytesIO()
pdf = pisa.pisaDocument(BytesIO(html.encode('UTF-8')), result, link_callback= fetch_pdf_resources, encoding='utf-8')
if not pdf.err:
return HttpResponse(result.getvalue(), content_type = "application/pdf")
return None
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.conf import settings
from django.shortcuts import render
from django.views.generic import View
# Create your views here.
from django.http import HttpResponse
from mi_pdf.utileria import render_pdf
class PDFPrueba(View):
'''
Пишем вывод пдф
'''
def get(self, request, *args, **kwargs):
pdf = render_pdf("profiles/dogovor/dogovor.html")
return HttpResponse(pdf ,content_type = "application/pdf")# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.conf import settings
from django.shortcuts import render
from django.views.generic import View
# Create your views here.
from django.http import HttpResponse
from mi_pdf.utileria import render_pdf
class PDFPrueba(View):
def get(self, request, *args, **kwargs):
pdf = render_pdf("profiles/dogovor/dogovor.html")
return HttpResponse(pdf ,content_type = "application/pdf")
<style>
@font-face { font-family: Arial; src: url(./static/fonts/arial.ttf); }
body{
font-family: Arial, sans-serif;
}
</style>
2018-06-06 12:09:37,455 {C:\Phyton\lib\site-packages\xhtml2pdf\document.py:85} DEBUG - pisaDocument options:
src = <_io.BytesIO object at 0x03CFCA80>
dest = <_io.BytesIO object at 0x04FCD030>
path = None
link_callback = <function fetch_resources at 0x04A44DF8>
xhtml = False
context_meta = None
2018-06-06 12:09:37,486 {C:\Phyton\lib\site-packages\xhtml2pdf\context.py:810} WARNING - getFile 'fonts/arial.ttf' 'E:\\work\\life\\__dummy__' 'E:\\work\\life\\__dummy__'
Traceback (most recent call last):
File "C:\Phyton\lib\site-packages\xhtml2pdf\context.py", line 796, in _getFileDeprecated
nv = self.pathCallback(name, relative)
File "E:\work\life\mi_pdf\utileria.py", line 24, in fetch_resources
path = os.path.join(settings.STATIC_ROOT, uri)
File "C:\Phyton\lib\ntpath.py", line 75, in join
path = os.fspath(path)
TypeError: expected str, bytes or os.PathLike object, not NoneType
2018-06-06 12:09:37,502 {C:\Phyton\lib\site-packages\xhtml2pdf\util.py:591} DEBUG - FileObject '', Basepath: None
2018-06-06 12:09:37,503 {C:\Phyton\lib\site-packages\xhtml2pdf\util.py:606} DEBUG - URLParts: (ParseResult(scheme='', netloc='', path='', params='', query='', fragment=''), '')
2018-06-06 12:09:37,505 {C:\Phyton\lib\site-packages\xhtml2pdf\util.py:668} DEBUG - Unrecognized scheme, assuming local file path
[06/Jun/2018 12:09:37] "GET /mi_pdf/ HTTP/1.1" 200 3659