짧은 파이썬 튜토리얼을 진행할 예정이지만 마지막 연습을 할 수 없습니다. 이 app.pyPython - 예외 lpthw.web 프레임 워크에서 "템플릿에 이름이없는 인덱스"가 있습니다.
import web
urls = (
'/', 'Index'
)
app = web.application(urls, globals())
render = web.template.render('templates/')
class Index(object):
def GET(self):
greeting = "Hello World"
return render.index(greeting = greeting)
if __name__ == "__main__":
app.run()
의 소스 코드와이
$def with (greeting)
<html>
<head>
<title>Gothons of Planet Percal #25</title>
</head>
<body>
$if greeting:
I just wanted to say <em style="color: green; font-size: 2em;">
greeting</em>.
$else:
<em>Hello</em>, world!
</body>
</html>
파일 app.py이 디렉토리 아래에 index.html을 뷰입니다 : C : \ 사용자 \ 루카스 \ 바탕 화면 \ 알아 파이썬 어려운 방법 \ EX50 \ gothonweb 빈 및 index.html을 \입니다에서 : C : 루카스 \ 바탕 화면 \ 사용자 \ \ 알아 파이썬 어려운 방법 \ EX50 \ gothonweb 템플릿
그래서, 내가 원하는 \ 예제 코드를 실행하기 위해 명령 프롬프트에 다음을 입력합니다 :
그 후C:\Python26\python.exe "C:\Users\Lucas\Desktop\Learn Python The Hard Way\ex50\gothonweb\bin\app.py"
, 에 "http : //0.0.0 : 8080" 내 브라우저 에 http://localhost:8080/로 이동하지만 다시
<type 'exceptions.AttributeError'> at/
No template named index
Python C:\Python26\lib\site-packages\web\template.py in _load_template, line 992
Web GET http://localhost:8080/
로 시작하는 긴 역 추적을 얻을 콘솔에 표시, 이렇게됩니다
무슨 일이 일어나고 있으며 어떻게 수정합니까?
미리 감사드립니다.
return render.Index(greeting = greeting)
그리고 당신의 urls
튜플의 요구를 : 당신은 몇 가지 오타가
감사합니다. index.html의 이름을 Index.html로 변경하고 귀하가 말한 바를 정확히 수행했지만 여전히 작동하지 않습니다. 예외는 이제 다음과 같습니다. 인덱스라는 템플릿이 없습니다. – Lucas
아, 경로를 보면'templates /'는 app.py와 관련이 있어야합니다 (일반적인 web.py에서는). 어쩌면'templates' 폴더와 app.py를 같은 장소로 옮겨 보시겠습니까? – zeekay
이것이 실패하면 web.py의 공식 버전을 다운로드하십시오. https://github.com/webpy/webpy/zipball/webpy-0.35 – zeekay