Search code examples
dockernginxflaskuwsgi

tiangolo/uwsgi-nginx-flask directory structure


What would be the directory structure required to successfully run a flask app inside a container using the base image tiangolo/uwsgi-nginx-flask.

The website mention only the location of the file main.py.

enter image description here

For more advance project

enter image description here

Where are we suppose to locate the folders 'Templates' and "Static' ?

Thanks a lot for your help.


Solution

  • .
    ├── Dockerfile
    └── app
        ├── app
        │   ├── __init__.py
        │   ├── main.py
        │   ├── static
        │   │   ├── script.js
        │   │   └── style.css
        │   └── templates
        │       └── index.html
        └── uwsgi.ini
    
    4 directories, 7 files
    

    You can locate templates & static wherever you like, however Flask will automatically know how to locate them if they are placed at the same path level as your app object creation script. If you decide to place them somewhere else, you may pass in static_folder and template_folder as keyword arguments with the absolute paths to these folders. If you want to see more details about the way in which Flask loads these files, you can set the EXPLAIN_TEMPLATE_LOADING config value to True (it defaults to False)

    from flask import Flask
    app = Flask(__name__)
    app.config.update(EXPLAIN_TEMPLATE_LOADING=True)
    

    This will log the output from the Jinja2 template loading engine, which is what Flask is using behind the scenes to locate its static files.

    You find more details about advanced Flask patterns from the official documentation.