Assets Management

Shopyo implements a Transparent Static Shadowing system. This allows you to use standard Flask asset patterns while maintaining a modular file structure.

How it Works

  1. Development (DEBUG=True): Shopyo intercepts requests to /static/modules/<module_name>/... and dynamically serves the file directly from your module’s static/ folder. You don’t need to run any commands to see your changes.

  2. Production (DEBUG=False): You run the collection command:

    shopyo collectstatic
    

    This physically copies all module assets into the root static/modules/ directory. This allows high-performance web servers like Nginx to serve all assets from a single physical location without touching the Python process.

The Legacy Way

Shopyo provides a helper get_static, though standard url_for is preferred in Shopyo 2.0.

from shopyo.api.assets import get_static

@module_blueprint.route('/img_test')
def img_test():
    return '<img src="{}">'.format(get_static('auth', 'logo.png'))

Summary

  • Global assets: Place in /static/.

  • Module assets: Place in /modules/<name>/static/.

  • Dev mode: Changes are instant.

  • Production: Run shopyo collectstatic before deploying.