2017-02-13 5 views
0

나는 변형 된 피라미드를 시험 중이다. 그러나 양식은 양식으로 렌더링되지 않고 순수한 문자열입니다.변형이있는 피라미드가 제대로 렌더링되지 않습니다. 순수한 문자열로 렌더링

@view_config(route_name='sign_up', renderer='templates/sign_up.jinja2') 
def sign_up(request): 
    schema = SignUpForm().bind(request=request) 

    button = deform.form.Button(name='SignUp', title = 'Sign Up') 
    form = deform.form.Form(schema, buttons=(button,)) 

    if request.method == 'POST': 
     try: 
      appstruct = form.validate(request.POST.items()) 

      # Save the data to database 
      print('saved') 
      print(appstruct['username']) 

      request.session.flash('your have succesfully registered') 

      return HTTPFound('/') 
     except deform.exception.ValidationFailure as e: 
      rendered_form = form.render() 
    else: 
     print('rendering the form') 
     rendered_form = form.render(); 

    return {'rendered_form': rendered_form} 

이것은 Jinja2 템플릿을 사용하는 제 HTML입니다.

<!DOCTYPE html> 
<html> 
    <head> 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> 
    </head> 
    <body> 
      {{rendered_form}} 
    </body> 
</html> 

모든 형태의 정보가

class SignUpForm(deform.schema.CSRFSchema): 
    username = colander.SchemaNode(
     colander.String(), 
     title = 'Username') 
    password = colander.SchemaNode(
     colander.String(), 
     title = 'Password') 

답변

3

Jinja2가 구성되어 브라우저에서 <form method=POST> 등 같은 순수한 리터럴 문자열 나타나에서 신뢰할 수없는 마크 업에서 XSS 공격을 피하기 위해 템플릿에 모든 변수를 자동-탈출 변수. {{ rendered_form | safe }}을 통해 변형 된 데이터를 자체적으로 이스케이프하도록 트러스트 할 수 있기 때문에 양식의 자동 이스케이프 기능을 해제 할 수 있습니다.

+0

완벽한 솔루션! 감사! – Bobby