【问题标题】:Allowing access to hidden folder from web. Plotly-dash允许从网络访问隐藏文件夹。破折号
【发布时间】:2020-10-05 12:08:31
【问题描述】:
我认为我的问题可能令人困惑,但我会更好地解释它。
我想要的是让我的应用程序使用 http 请求返回位于隐藏目录中的文件,例如,如果我发出 http://mywebsite.com/assets/style.css 请求,我会得到 style.css 文件,但是我也想让我的应用程序从一个隐藏目录,比如http://mywebsite.com/.hidden-folder/file(在这种情况下,我得到 200 响应,但没有请求文件)
这对我来说是一个新问题,因为我不熟悉 Web 开发,所以我不知道从哪里开始。
我为什么要问这个?
我正在使用certbot 在我的网站中启用https,我需要允许从网络访问.well-known/acme-challenge/ 文件夹,我也很好奇。
【问题讨论】:
标签:
python
flask
https
plotly-dash
certbot
【解决方案1】:
这可能对你有帮助
目录结构
├── api
│ ├── app.py
│ ├── __init__.py
├── build
│ ├── .hidden
│ │ └── test.json
#app.py
app = Flask(__name__,static_folder='../build',static_url_path="/")
@app.route('/hidden/<filename>')
def hello_world2(filename):
return app.send_static_file(os.path.join(".hidden", filename))
# or
@app.route('/<path>/<filename>')
def hello_world3(path, filename):
return app.send_static_file(os.path.join(path, filename))
>> curl 127.0.0.1:5000/hidden/test.json
{
"test": "test"
}
>> curl 127.0.0.1:5000/.hidden/test.json
{
"test": "test"
}