使用 aiohttp 提供的静态文件无效
Invalid serving of static file with aiohttp
我有一个简单的 aiohttp 单页网络应用程序,想用 aiohttp 本身提供静态文件
app.router.add_static('/static/', os.path.join(root_path, 'static'))
但是从浏览器访问资源时出现错误
Uncaught SyntaxError: Invalid or unexpected token
因为 index.js
文件以某种意外的方式提供。
环境:
aiohttp==1.0.3
、Python 3.5.2
、Ubuntu 16.04.1 LTS
文件是保存不当还是 OS 错误或 aiohttp 本身有问题?
所以错误的原因是 os sendfile
以某种错误的方式 caching/serving 文件。
export AIOHTTP_NOSENDFILE=1
解决了一个问题。 Link 更多详情 here。
当然,对于生产环境,使用 nginx 为您的静态文件提供服务。
我有一个简单的 aiohttp 单页网络应用程序,想用 aiohttp 本身提供静态文件
app.router.add_static('/static/', os.path.join(root_path, 'static'))
但是从浏览器访问资源时出现错误
Uncaught SyntaxError: Invalid or unexpected token
因为 index.js
文件以某种意外的方式提供。
环境:
aiohttp==1.0.3
、Python 3.5.2
、Ubuntu 16.04.1 LTS
文件是保存不当还是 OS 错误或 aiohttp 本身有问题?
所以错误的原因是 os sendfile
以某种错误的方式 caching/serving 文件。
export AIOHTTP_NOSENDFILE=1
解决了一个问题。 Link 更多详情 here。
当然,对于生产环境,使用 nginx 为您的静态文件提供服务。