Get path relative to executed flask app

后端 未结 1 1127
眼角桃花
眼角桃花 2020-12-12 01:56

In my flask app I recreate a sqlite database at every start.
For this I use code as shown on the official webpage

My project structure looks like this

         


        
相关标签:
1条回答
  • 2020-12-12 02:23

    This exact use case happens to be the example used in the documentation for flask's open_resource API call as well as the blueprint documentation linked in your question.

    Specifically, the reference doc says:

    To see how this works, consider the following folder structure:

    /myapplication.py 
         /schema.sql 
         /static
             /style.css 
         /templates
             /layout.html
             /index.html 
    

    If you want to open the schema.sql file you would do the following:

     with app.open_resource('schema.sql') as f:
         contents = f.read()
         do_something_with(contents)
    
    0 讨论(0)
提交回复
热议问题