2010-05-21 6 views
6

보기가있는 경우보기 파일의 < 머리 >에 정적 파일 (CSS 및 JS)을 어떻게로드 할 수 있습니까?web2py의보기 HTML에서 정적 파일을로드하는 방법은 무엇입니까?

layout.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{{=T.accepted_language or 'en'}}"> 
    <head> 
     <title>{{=response.title or request.application}}</title> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
     <!-- include requires CSS files 
     {{response.files.append(URL(request.application,'static','base.css'))}} 
     {{response.files.append(URL(request.application,'static','ez-plug-min.css'))}} 
     --> 
     {{include 'web2py_ajax.html'}} 
    </head> 
    <body> 
     {{include}} 
    </body> 
</html> 

위의 예에서 myview.html

{{extend 'layout.html'}} 
{{response.files.append(URL(r=request,c='static',f='myview.css'))}} 

<h1>Some header</h1> 
<div> 
    some content 
</div> 

은 "myview.css"파일 web2py 무시하거나하여 벗겨 어느 브라우저.

그래서이 CSS 파일과 같은 페이지 별 파일을로드하는 가장 좋은 방법은 무엇입니까? 차라리 레이아웃에 모든 정적 파일을 채우지 않을 것입니다.

답변

7

에서 처음 두 줄 1.78.1 및 1.78.2 버그가이 작업을 허용하지 않았다 있었다 마음 것을

{{response.files.append(URL(r=request,c='static',f='myview.css'))}} 
{{extend 'layout.html'}} 

역 myview.html. 같은 날에 1.78.3에서 수정되었습니다. response.file.append (...)도 필요한 controller 액션에서 이동할 수 있습니다. 확장하기 전에 논리를 넣지 않아도되지만 확장보기에 전달할 변수를 정의합니다.

+0

Perfect. 감사! – MikeWyatt

관련 문제