Great question! Since you’re:
- Using Blueprints with their own
static folders (👈 good modular design),
- Sharing common templates like
base.html and navigation.html, likely in a shared/global template folder,
- And want
passport_photo.html to use blueprint-local static files (not default /static/),
You need to properly set the static file paths using url_for('blueprint_name.static', filename='path/to/file').
✅ Solution
To correctly include static files from a blueprint's local static/ folder in passport_photo.html, change paths like this:
In passport_photo.html
<!-- Static CSS from passport_photo blueprint -->
<link rel="stylesheet" href="{{ url_for('passport_photo.static', filename='css/styles.css') }}">
<!-- Static JS from passport_photo blueprint -->
<script src="{{ url_for('passport_photo.static', filename='js/main.js') }}" nonce="{{ nonce }}"></script>
<!-- Static image from passport_photo blueprint -->
<img src="{{ url_for('passport_photo.static', filename='images/logo.png') }}" alt="Logo">
Now Flask will resolve these like so:
/passport_photo_static/css/styles.css
/passport_photo_static/js/main.js
/passport_photo_static/images/logo.png
Which correctly maps to the static/ folder inside the passport_photo/ blueprint directory, because of:
passport_photo = Blueprint(
'passport_photo',
__name__,
static_folder='static',
static_url_path='/passport_photo_static'
)
🧱 Folder Structure Assumption
Just to clarify, your folder structure looks something like this:
technology_apps/
├── passport_photo/
│ ├── __init__.py
│ ├── routes.py
│ ├── static/
│ │ ├── css/
│ │ │ └── styles.css
│ │ └── js/
│ │ └── main.js
│ └── templates/
│ └── passport_photo.html
├── templates/ <-- shared templates
│ ├── base.html
│ └── navigation.html
🧩 If You're Extending base.html
In passport_photo.html, you would typically do:
{% extends 'base.html' %}
{% block content %}
<h1>Passport Photo Page</h1>
<img src="{{ url_for('passport_photo.static', filename='images/sample.jpg') }}" alt="Photo Example">
{% endblock %}