允许从Web访问隐藏文件夹。破折号

问题描述 投票:0回答:1

我认为我的问题可能令人困惑,但我会更好地解释。

[我想要的是使用http请求将我的应用返回文件放置在隐藏目录中,例如,如果我发出http://mywebsite.com/assets/style.css请求,则会得到style.css文件,但是我也想从隐藏目录,例如http://mywebsite.com/.hidden-folder/file(在这种情况下,我得到一个200响应,但没有请求的文件)

这对我来说是一个新问题,因为我不熟悉Web开发,所以我不知道从哪里开始。

我为什么要问这个?

我正在使用certbot在我的网站中启用https,并且我需要允许从Web访问.well-known/acme-challenge/文件夹,我也很好奇。

python flask https plotly-dash certbot
1个回答
0
投票

这可能会对您有帮助

目录结构

├── 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"
}   

© www.soinside.com 2019 - 2024. All rights reserved.