2014-03-26 1 views
3

python을 처음 접했을 때 python anywhere에 새롭게 등장한 트리플 뉴비 위협에 대해 미리주의 깊게 살펴보십시오.pythonanywhere + flask : 웹 사이트에 '처리되지 않은 예외'라고 나와 있습니다. 스택 추적을 인쇄하는 디버거를 얻는 방법?

[pythonanywhere 루트는,

# A very simple Flask Hello World app for you to get started with... 

from flask import Flask 
from flask import render_template # for templating 
#from flask import request # for handling requests eg form post, etc 

app = Flask(__name__) 
app.debug = True #bshark: turn on debugging, hopefully? 

@app.route('/') 
#def hello_world(): 
# return 'Hello from Flask! wheee!!' 
def buildOrg(): 
    orgname = 'ACME Inc' 
    return render_template('index.html', orgname) 

그리고 내가 사이트를 공격 할 때

<!doctype html> 
<head><title>Test01 App</title></head> 
<body> 
{% if orgname %} 
    <h1>Welcome to {{ orgname }} Projects!</h1> 
{% else %} 
<p>Aw, the orgname wasn't passed in successfully :-(</p> 
{% endif %} 
</body> 
</html> 

/templates/index.html [pythonanywhere 루트]에서를 /mysite/test01.py '처리되지 않은 예외'가 발생합니다 : 적어도 문제를 찾기 시작할 곳에서 디버거를 뱉어 낼 수 있습니까?

+2

"웹"탭에서 오류 로그를보십시오. –

+0

omg ... thx! 그것은 'TypeError : render_template()는 1 개의 위치 인수를 취하지 만 2는 주어진 것입니다.'클래스 메소드가 첫 번째 인수가 자기가되기를 기대하는 것은 그런 것입니까? hrm ... – babyshark

+0

또한, 거기에있는 모든 파이썬 오류를 볼 수있는 대답으로 귀하의 의견을 수락하고 싶습니다. 대답으로 다시 말하면 받아 들일 수 있습니다. – babyshark

답변

2
문제는 render_template입니다

는 하나 개의 위치 인수를 기대하고, 나머지 :

return render_template('index.html', orgname) 

사람 :

flask.render_template(template_name_or_list, **context) 

    Renders a template from the template folder with the given context. 
    Parameters: 
     template_name_or_list – the name of the template to be rendered, 
     or an iterable with template names the first one existing will be rendered 
     context – the variables that should be available in the context of the template. 

그래서,이 줄을 변경 키워드 전용 인수로 전달됩니다. 그래서, 코드를 변경해야합니다. 로 : 첫 번째 부분에 대한

def buildOrg(): 
    orgname = 'ACME Inc' 
    return render_template('index.html', name=orgname) 

, 당신은 pythonanywhere.com에 Web 탭에서 오류 로그를 찾을 수 있습니다.

+0

오류 로그에 나를 가리키기 때문에 수락합니다. 그러나 render_template에 대한 수정은 작동하지 않습니다. (Omid Raha에 대한 제 응답 참조) ... – babyshark

+0

@ user3465444이 실수를 다른 곳에서도 수정 했습니까? (변경 후 응용 프로그램을 다시로드하는 것을 잊지 마십시오.) –

+0

안녕하십니까 ... orgname = orgname param all; 문제는 내 템플릿 폴더가 올바른 위치에 있지 않다는 것입니다. 일단 내가 그것을 옮겼 더니 모든 것이 효과가있었습니다. 예! 모든 도움에 감사드립니다. – babyshark

1

의 이름도 전달해야합니다.템플릿에서 render_template으로 사용되는 변수입니다.

flask.render_template : 인수의

return render_template('index.html', orgname=orgname) 
+0

감사합니다. 2014-03-26 19 : 08 : 40,801 : render_template ('index.html', orgname = orgname)을 반환하십시오. 2014-03-26 19 : 08 : 40,801 : TypeError : render_template()는 1 개의 위치를 ​​취합니다. 논증 그러나 2는 주어졌다 – babyshark

+1

다시 안녕 Omid - 당신이 바뀌었던 것은 나온다! 내 템플릿 폴더가 단순히 잘못된 위치에있었습니다. 플라스크 빠른 시작 가이드를 잘못 읽었습니다. 일단 올바른 위치에 있으면 orgname = orgname으로 설정된 두 번째 매개 변수가 완벽하게 작동했습니다. 고맙습니다! – babyshark