我是 Python 和 Flask 的新手。我的应用程序根目录中有一个模板文件夹,其中有两个文件。
<!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')
所以当我启动服务器并说http://0.0.0.0:5000/appointment
我得到
"<!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>"
这意味着模板正在工作,但浏览器将响应视为字符串而不是 html。我究竟做错了什么。