Flask Installation
Add Simple Commenter to your Flask application by adding the script to your Jinja templates.
Important: The public key in your script must match a project in your Simple Commenter dashboard. If it doesn't match, the widget won't load.
Basic Installation
Add the script to your base template:
<!-- templates/base.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{% block title %}My Flask App{% endblock %}</title>
</head>
<body>
{% block content %}{% endblock %}
<!-- Add Simple Commenter before closing body -->
<script
src="https://simplecommenter.com/js/comments.min.js?id=sc_your_public_key"
defer
></script>
</body>
</html>
Your other templates extend this:
<!-- templates/home.html -->
{% extends "base.html" %}
{% block title %}Home{% endblock %}
{% block content %}
<h1>Welcome</h1>
{% endblock %}
Replace sc_your_public_key with your project's public key from the Simple Commenter dashboard.
Using Flask Config
Store the public key in your Flask configuration:
# config.py or app.py
class Config:
SIMPLE_COMMENTER_KEY = "sc_your_public_key"
Make it available to templates:
# app.py
from flask import Flask
app = Flask(__name__)
app.config.from_object('config.Config')
@app.context_processor
def inject_simple_commenter():
return dict(
simple_commenter_key=app.config.get('SIMPLE_COMMENTER_KEY', '')
)
Use in template:
<!-- templates/base.html -->
{% if simple_commenter_key %}
<script
src="https://simplecommenter.com/js/comments.min.js?id={{ simple_commenter_key }}"
defer
></script>
{% endif %}
Environment Variables
Use environment variables for different environments:
# app.py
import os
app.config['SIMPLE_COMMENTER_KEY'] = os.environ.get(
'SIMPLE_COMMENTER_KEY',
''
)
# .env or environment
SIMPLE_COMMENTER_KEY=sc_your_public_key
With python-dotenv:
# app.py
from dotenv import load_dotenv
load_dotenv()
app.config['SIMPLE_COMMENTER_KEY'] = os.getenv('SIMPLE_COMMENTER_KEY')
Conditional Loading
Only load on certain routes:
# app.py
@app.context_processor
def inject_simple_commenter():
from flask import request
# Don't show on admin routes
show_widget = not request.path.startswith('/admin')
return dict(
show_feedback_widget=show_widget,
simple_commenter_key=app.config.get('SIMPLE_COMMENTER_KEY', '')
)
<!-- templates/base.html -->
{% if show_feedback_widget and simple_commenter_key %}
<script
src="https://simplecommenter.com/js/comments.min.js?id={{ simple_commenter_key }}"
defer
></script>
{% endif %}
Page-Specific Widget
Use template blocks:
<!-- templates/base.html -->
{% block extra_scripts %}{% endblock %}
</body>
<!-- templates/feedback_page.html -->
{% extends "base.html" %}
{% block extra_scripts %}
<script
src="https://simplecommenter.com/js/comments.min.js?id=sc_your_public_key"
defer
></script>
{% endblock %}
Flask Blueprints
If using blueprints, the context processor works across all blueprints when registered on the app:
# app.py
app = Flask(__name__)
@app.context_processor
def inject_simple_commenter():
return dict(simple_commenter_key='sc_your_public_key')
# Register blueprints
from views import main_bp
app.register_blueprint(main_bp)
Verifying Installation
- Run your development server (
flask run) - Open your app in the browser
- Look for the feedback widget button
- Check browser console (F12) for errors
- Navigate to different routes
Troubleshooting
Widget not appearing
- Check that your template extends base.html correctly
- Verify the public key matches your dashboard settings
- View page source to confirm the script is present
- Look for JavaScript errors in browser console
Template not extending correctly
- Ensure
{% extends "base.html" %}is at the top - Check the template file is in the correct directory
- Verify Flask's template folder configuration
Blueprint-specific issues
- Context processors on the app work for all blueprints
- Blueprint-specific context processors only work for that blueprint
- Register app-wide for consistent behavior
Production deployment
- Ensure your production domain is registered in the dashboard
- The script is hosted externally, unaffected by Flask's static file handling
- Works with Gunicorn, uWSGI, etc.
Need help? Contact support.