2013-10-11 10 views
5

Python ve Flask'ta yeniyim. Uygulamamın kökünde iki dosya içeren bir şablonum var. i sunucuyu başlatmak ve http://0.0.0.0:5000/appointment derkenOluşturulan şablonu Flask-Restful ile döndürme, tarayıcıda HTML'yi gösterir

<!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> 

ve

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

Ve sonra ben şu var fonksiyonu

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') 

yüzden Anlamı

"<!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>" 

olsun şablonlar ar e çalışıyor ancak tarayıcı, yanıtı bir Dize olarak değil html olarak ele alıyor. Neyi yanlış yapıyorum.

cevap

11

Alımı buna göre değiştirdim. İçerik türünü ayarlamak hile yaptı.

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

Dosya uzantısı '.html' mü? – tbicr