2017-11-09 6 views

답변

1

또 다른 방법은 before_serve_document 할미새 후크에 후크가 될 수 있습니다.

http://docs.wagtail.io/en/v1.13/reference/hooks.html#document-serving

당신은 어떻게 여기 후크 작품을 보여주는 매우 거친 예입니다,이 방법으로 문서에 따라 응답을 사용자 정의 할 수 있습니다.

그래도 파일을 표시하는 볼 수있는 URL을 생성하는 방법을 해결해야합니다.

from wagtail.wagtailcore import hooks 
from django.shortcuts import redirect 


@hooks.register('before_serve_document') 
def serve_document(document, request): 
    # eg. use document.file_extension, document.url, document.filename 
    if document.file_extension == 'pdf': 
     google_view_pdf_base = 'https://docs.google.com/viewer?url=' 
     # document.url is a relative URL so more work needed here 
     # also URL should probably be URL encoded 
     redirect_url = google_view_pdf_base + document.url 
     # must return an instance of HTTPResponse 
     return redirect(redirect_url) 
    # no return means the normal page serve will operate 
1

문서에 대한 링크를 다운로드하는 것은 꽤 표준 적인데, 대부분 브라우저 내에서 문서 미리보기가 각 브라우저마다 실제로 다르기 때문입니다.

URL을 PDF로 구문 분석하고 target="_blank" 특성을 추가하는 템플릿 필터를 추가 할 수 있습니다.

이 온라인으로 호스팅되는 PDF를 들어, 대부분의 브라우저에서 작동 될 수 있습니다 사용자 정의 필터를 만드는 방법 https://stackoverflow.com/a/27392750/8070948

이에 https://docs.djangoproject.com/en/1.11/howto/custom-template-tags/#registering-custom-filters