flask 渲染拼接模版

图片

test.py
from flask import Flask,render_template,make_response
from flask_restful import Api, Resource, reqparse
import  werkzeug
 
app = Flask(__name__)
api = Api(app)
 
class AppointmentController(Resource):
    def __init__(self):
        pass
    def get(self):
        headers = {'Content-Type': 'text/html'}
        return make_response(render_template('index.html'),200,headers)
 
api.add_resource(AppointmentController, '/upload')
 
 
if __name__ == '__main__':
  app.run(debug=True)
base.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">
  <h2>index parent!!!</h2>
  <div class="content container">
    {% block main %}{% endblock main %}
  </div>
  </div>
</body>
</html>
index.html
{% extends 'base.html' %}
{% block title %}Page Title{% endblock title %}
{% block main %}
    <h2>This is a child template.</h2>
{% endblock main %}

 

 
 
 
 
 
 
 
 
 
 
 
 
 
 

posted @ 2020-12-23 22:50  anobscureretreat  阅读(148)  评论(0编辑  收藏  举报