2013-10-11 3 views
5

저는 Python과 Flask를 처음 사용합니다. 내 응용 프로그램의 루트에 두 개의 파일이있는 템플릿 폴더가 있습니다. 내가 서버를 시작하고 http://0.0.0.0:5000/appointment을 말할 때Flask-Restful으로 렌더링 된 템플릿을 반환하면 브라우저에 HTML이 표시됩니다.

<!DOCTYPE html> 
    <html lang="en"> 
    <head> 
    <title>{% block title %}{% endblock title %}</title> 

    <link href="http://netdna.bootstrapcdn.com/bootswatch/2.3.2/united/bootstrap.min.css" rel="stylesheet"> 
    <link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/ bootstrap-responsive.min.css" rel="stylesheet"> 
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> 
    <script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script> 
</head> 
<body> 
    <div id="main"> 
    <div class="utility-nav navbar navbar-fixed-top"> 
    <div class="navbar-inner"> 
    <div class="container"> 
     {# Navbar goes here. #} 
    </div> 
    </div> 
    </div> 
    <div class="content container"> 
    {% block main %}{% endblock main %} 
    </div> 
    </div> 
</body> 
</html> 

{% extends 'base.html' %} 
{% block title %}Page Title{% endblock title %} 
{% block main %} 
    <h2>This is a child template.</h2> 
{% endblock main %} 

그리고 난 다음 한 기능

from flask.ext.restful import Resource,request,reqparse 
from app.business.login import Login 
from app.business.appointments import Appointments 
from app.models.models import User, Address,Appointment 
from flask import render_template 
    class AppointmentController(Resource): 
     def __init__(self): 
      pass 
     def get(self): 
     return render_template('index.html') 

은 그래서 의미

"<!DOCTYPE html>\n <html lang=\"en\">\n <head>\n  <title>Page Title</title>\n \n  <link href=\"http://netdna.bootstrapcdn.com/bootswatch/2.3.2/united/bootstrap.min.css\" rel=\"stylesheet\">\n  <link href=\"http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/ bootstrap-responsive.min.css\" rel=\"stylesheet\">\n  <script src=\"http://code.jquery.com/jquery-1.9.1.min.js\"></script>\n  <script src=\"http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js\"></script>\n</head>\n<body>\n <div id=\"main\">\n <div class=\"utility-nav navbar navbar-fixed-top\">\n <div class=\"navbar-inner\">\n <div class=\"container\">\n  \n </div>\n </div>\n </div>\n <div class=\"content container\">\n \n\t<h2>This is a child template.</h2>\n\n </div>\n </div>\n</body>\n</html>" 

수 템플릿 ar e는 작동하지만 브라우저는 html이 아닌 String으로 응답을 처리합니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까.

답변

11

이에 따라 수정되었습니다. 콘텐츠 유형을 설정하는 것이 트릭을 만들었습니다.

class AppointmentController(Resource): 
    def __init__(self): 
     pass 
    def get(self): 
     headers = {'Content-Type': 'text/html'} 
     return make_response(render_template('index.html'),200,headers) 
+0

파일 확장자는'.html'입니까? – tbicr

관련 문제