Skip to content

duplicate in app.py and helpers.py related to template_dir #25

@ockan

Description

@ockan

duplicate in app.py and helpers.py related to template_dir
in app.py:

    def __init__(
       ...
    ):
        ...

        if static_folder is None:
            static_folder = "static"
        if not os.path.isabs(static_folder):
            static_folder = os.path.join(root_path, static_folder)
        self.static_folder = static_folder

        if template_folder is None:
            template_folder = "templates"
        if not os.path.isabs(template_folder):
            template_folder = os.path.join(root_path, template_folder)
        self.template_folder = template_folder

and in helpers.py

def render_template(template_name: str, **context) -> Response:
    try:
        import os

        from jinja2 import Environment, FileSystemLoader, select_autoescape

        # Get template directory
        template_dir = context.pop("_template_dir", None)

        # If no explicit template_dir, try to get from current app
        if template_dir is None:
            try:
                current_app = _get_current_object()
                template_dir = (
                    getattr(current_app, "template_folder", None) or "templates"
                )
            except RuntimeError:
                # No app context, use default
                template_dir = "templates"

        if not os.path.exists(template_dir):
            os.makedirs(template_dir, exist_ok=True)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions