2017-11-01 10 views
0

달걀 파일에서 청사진을로드하는 모듈 플라스크 애플리케이션을 만들지 만 해당 청사진은 해당 패키지의 템플릿을 렌더링해야합니다.달걀 패키지의 플라스크 하중 템플릿

이 내 프로젝트가 같은 모습입니다 : 이제

some folders/ 
templates/ #the base folders 
static/ 
blueprints/ 
    |- blueprint1.egg 
    | |- templates/ #inside the .egg 
    | |- some other folders/ 
    | |- main.py 
    |- blueprint2.egg 
    |- templates/ 
    |- some other folders/ 
    |- main.py 
my_flask_main.py 

내가 가져 그 .egg에서 correcly 청사진을 등록하지만 어떻게 내가 그들을을가 즉석에서 추출 .egg에서 그 템플릿을로드 할 수 있습니다, 아니면 .egg에서 직접 읽는 것이 더 나은가요?

사전에

감사 (OBV는 DEV 모드에서 청사진이 내가 청사진을 포장하는 경우도를로드하는 방법이 필요합니다, 작동, 포장되지 않은 경우).

답변

0

몇 가지 연구와 테스트 후, 며칠 후, 나는 마침내 그렇게 할 수있는 방법을 발견

bp_dummy = Blueprint('dummy', __name__, template_folder='templates') 

bp_dummy.jinja_loader = jinja2.ChoiceLoader([ 
    bp_dummy.jinja_loader, 
    jinja2.PackageLoader(__name__) # in the same folder will search the 'templates' folder 
]) 

첫째, 모든 청사진 인스턴스에서 당신은 템플릿 폴더 경로를 정의하고 기본 jinja2 템플릿 폴더를 오버라이드 (override) 할 필요가 있습니다 (기본적으로 FileSystemLoader 여야 함) 모듈을 패키지화하면 기본 로더가 실패하고 PackageLoader가 작동합니다.