Flask Installation

Add Simple Commenter to your Flask application by adding the script to your Jinja templates.

Important: The domain in your script must exactly match the domain you registered in your Simple Commenter dashboard. If they don'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"
        data-domain="your-domain.com"
        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 your-domain.com with your actual domain from the Simple Commenter dashboard.

Using Flask Config

Store the domain in your Flask configuration:

# config.py or app.py
class Config:
    SIMPLE_COMMENTER_DOMAIN = "your-domain.com"

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_domain=app.config.get('SIMPLE_COMMENTER_DOMAIN', '')
    )

Use in template:

<!-- templates/base.html -->
{% if simple_commenter_domain %}
<script
    src="https://simplecommenter.com/js/comments.min.js"
    data-domain="{{ simple_commenter_domain }}"
    defer
></script>
{% endif %}

Environment Variables

Use environment variables for different environments:

# app.py
import os

app.config['SIMPLE_COMMENTER_DOMAIN'] = os.environ.get(
    'SIMPLE_COMMENTER_DOMAIN',
    ''
)
# .env or environment
SIMPLE_COMMENTER_DOMAIN=your-domain.com

With python-dotenv:

# app.py
from dotenv import load_dotenv
load_dotenv()

app.config['SIMPLE_COMMENTER_DOMAIN'] = os.getenv('SIMPLE_COMMENTER_DOMAIN')

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_domain=app.config.get('SIMPLE_COMMENTER_DOMAIN', '')
    )
<!-- templates/base.html -->
{% if show_feedback_widget and simple_commenter_domain %}
<script
    src="https://simplecommenter.com/js/comments.min.js"
    data-domain="{{ simple_commenter_domain }}"
    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"
    data-domain="your-domain.com"
    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_domain='your-domain.com')

# Register blueprints
from views import main_bp
app.register_blueprint(main_bp)

Verifying Installation

  1. Run your development server (flask run)
  2. Open your app in the browser
  3. Look for the feedback widget button
  4. Check browser console (F12) for errors
  5. Navigate to different routes

Troubleshooting

Widget not appearing

  • Check that your template extends base.html correctly
  • Verify the domain 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.

Was this page helpful?