首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >包括在SimpleHTTPServer?

包括在SimpleHTTPServer?
EN

Stack Overflow用户
提问于 2014-03-03 12:40:47
回答 1查看 359关注 0票数 3

我已经开始使用Mac中的Python来帮助前端模板,而不是SimpleHTTPServer。我喜欢简单,但我想知道是否有一种方法可以使用include嵌入页面中可重复的部分(主要是页眉/页脚)?

我通常会使用PHP,但我不认为这是SimpleHTTPServer的一个选项,所以我想知道是否还有其他方法可以轻松地做到这一点?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-07-01 23:43:05

您可以在请求的do_GET()方法中做任何您想做的事情,包括解析它以获得包含指令,如下代码大纲所示:

代码语言:javascript
复制
class IncludeHandler(SimpleHTTPRequestHandler):

    def do_GET(self):
        # self.path is the requested file
        complete_file = process_included_files(self.path)  # include the included files 

        # serve the file. These lines come
        # straight from the http.server source code

        self.send_response(200)
        self.send_header("Content-type", "text/html") # or whatever the mime type is
        fs = os.fstat(complete_file.fileno())
        self.send_header("Content-Length", str(fs[6]))
        self.end_headers()

        self.copyfile(complete_file, self.wfile)
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22147086

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档