前端是webpack+React的一个小demo,直接访问页面无报错
使用web.py作为本地服务器时 控制台输出 Uncaught SyntaxError: Unexpected token <
经验证发现 代码中出现
<script type="text/javascript" src="./out/bundle.js"></script>
时报错
bundle.js为webpack打包出的文件
前端代码在
https://github.com/shisi1010/...
python代码
# -*- coding: utf-8 -*-
import web
render = web.template.render('react_webpack')
urls = (
'/index', 'index',
'/(.*)', 'hello'
)
app = web.application(urls, globals())
class index:
def GET(self):
query = web.input()
return query
class hello:
def GET(self, name):
return render.xxx()
if __name__ == "__main__":
app.run()
是web.py根据正则表达式/(.*)把/out/bundle.js路由解析到hello函数了,配置下静态文件目录应该就可以了

chrome的调试可以看到bundle.js其实不是js文件