V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
GjriFeu
V2EX  ›  Python

Python web ,前端一个请求,后端返回一个 html 文件, html 里面请求了很多 js 和 css,确定都返回给前端,为什么前端页面不渲染。。网页保存在本地后再打开是可以看到渲染后的页面的,这是为什么。。求解

  •  
  •   GjriFeu · 2017-04-28 14:42:17 +08:00 · 5333 次点击
    这是一个创建于 2526 天前的主题,其中的信息可能已经有所发展或是发生改变。
    15 条回复    2017-04-29 09:31:32 +08:00
    w88975
        1
    w88975  
       2017-04-28 14:45:53 +08:00   ❤️ 1
    看下 mime type 是不是对的
    GjriFeu
        2
    GjriFeu  
    OP
       2017-04-28 14:55:09 +08:00
    @w88975 不怎么会前端。。刚刚查了下 mime type 是什么,但是无法定位我的代码是否存在这个问题。。
    GjriFeu
        3
    GjriFeu  
    OP
       2017-04-28 14:56:45 +08:00
    @w88975 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 里面的设置
    tumbzzc
        4
    tumbzzc  
       2017-04-28 15:21:59 +08:00
    F12 看请求状态
    GjriFeu
        5
    GjriFeu  
    OP
       2017-04-28 15:24:04 +08:00
    @tumbzzc Request Method:GET
    Status Code:304 Not Modified
    GjriFeu
        6
    GjriFeu  
    OP
       2017-04-28 15:24:40 +08:00
    @tumbzzc @w88975 set_header("Content-Type", "text/html")返回时加了一句这个
    tumbzzc
        7
    tumbzzc  
       2017-04-28 15:26:30 +08:00
    直接贴个 gist 代码吧
    GjriFeu
        8
    GjriFeu  
    OP
       2017-04-28 15:27:46 +08:00
    @tumbzzc 什么是 gist。。
    flaneurse
        9
    flaneurse  
       2017-04-28 16:01:45 +08:00 via Android
    @GjriFeu 就是让你把代码放出来
    GjriFeu
        10
    GjriFeu  
    OP
       2017-04-28 16:14:26 +08:00
    @tumbzzc @flaneurse 这是 handler 处理逻辑
    if self.path_segments[0] == 'fac':
    self.render('template_html/fac.html')
    elif self.path_segments[0] == 'fac_files':
    self.render('template_html/+self.path_segments[1]') #获取 js/css 脚本
    bdbai
        11
    bdbai  
       2017-04-28 18:19:41 +08:00 via Android
    F12 再琢磨琢磨,看看控制台、DOM 那里是否正常,有没有红的请求等等。按住刷新,清空缓存刷新试试。
    crisewng
        12
    crisewng  
       2017-04-28 18:51:05 +08:00
    self.render('template_html/+self.path_segments[1]') 这段你确定能拿到 js? 应该是这样子把 self.render('template_html/'+self.path_segments[1])
    GjriFeu
        13
    GjriFeu  
    OP
       2017-04-28 19:32:10 +08:00
    @crisewng 我手打的,写错了,代码里面是这样的
    scriptB0y
        14
    scriptB0y  
       2017-04-28 21:42:11 +08:00
    @GjriFeu 把这一部分贴出来看看

    Chrome>开发者工具>Network>页面的 Response Headers
    GjriFeu
        15
    GjriFeu  
    OP
       2017-04-29 09:31:32 +08:00
    @scriptB0y @bdbai 问题已解决,原因是 mime type 不对,js,css 都要设置 Content-Type
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3255 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 14:16 · PVG 22:16 · LAX 07:16 · JFK 10:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.