找不到Django静态文件1.11

时间:2018-06-06 00:31:58

标签: django-1.11 weasyprint

我读过这个: Django - Static file not found

但我仍然感到困惑,因为我的某个项目应用的静态文件正在投放。我认为问题在于django-weasyprint设置:

settings.py

>>> settings.BASE_DIR
'/Users/blakepowell/django_/direct2'
>>> settings.STATIC_ROOT
'/static/'
>>> settings.BASE_DIR
'/Users/blakepowell/django_/direct2'
>>> settings.DJANGO_ROOT
'/Users/blakepowell/django_/direct2'
>>> settings.STATICFILES_DIRS
['/Users/blakepowell/django_/direct2/flights/static/', '/Users/blakepowell/django_/direct2/pdf_output/static/']

pdf_output / views.py per django-weasyprint

class PrintView(WeasyTemplateResponseMixin, PDFView):
    # None
    pdf_stylesheets = [
    settings.STATIC_ROOT + 'pdf_output/static/pdf_output/css/pdf_output.css',
    ]

错误

[Errno 2] No such file or directory: '/static/pdf_output/static/pdf_output/css/pdf_output.css'

任何想法?

1 个答案:

答案 0 :(得分:0)

在您的settings.py中,您有

STATICFILES_DIRS = [
    '/Users/blakepowell/django_/direct2/flights/static/',
    '/Users/blakepowell/django_/direct2/pdf_output/static/'
]

我想? 现在,您可以通过/static/

直接访问这些directorys中的文件
class PrintView(WeasyTemplateResponseMixin, PDFView):
    # None
    pdf_stylesheets = [
        '/static/pdf_output/css/pdf_output.css',
    ]

如果您的css文件位于/Users/blakepowell/django_/direct2/pdf_output/static/pdf_output/css/pdf_output.css

或通过

class PrintView(WeasyTemplateResponseMixin, PDFView):
    # None
    pdf_stylesheets = [
        '/static/css/pdf_output.css',
    ]

如果您的css文件位于/Users/blakepowell/django_/direct2/pdf_output/static/css/pdf_output.css

我无法看到您的css文件在您的计算机上的位置。为什么你使用两个静态'文件夹?