---
type: "Source File"
title: "\"\"\"CopeCheck Funding — Funding transparency and grant application hub.\"\"\""
description: "\"\"\"CopeCheck Funding — Funding transparency and grant application hub.\"\"\" from flask import ( Flask, render_template, request, redirect, url_for, flash, make_response, ) from datetime import datetime import db app =."
resource: "https://funding.copecheck.com"
tags: ["copecheck", "funding", "source-file", "py"]
timestamp: "2026-09-26T08:28:11Z"
site: "funding"
source_path: "copecheck-funding/app.py"
---

# """CopeCheck Funding — Funding transparency and grant application hub."""

Source path: `copecheck-funding/app.py`  
Index snapshot generated: `2026-11-24T13:27:52Z`  
File modified: `2026-09-26T08:28:11Z`

```py
"""CopeCheck Funding — Funding transparency and grant application hub."""

from flask import (
    Flask,
    render_template,
    request,
    redirect,
    url_for,
    flash,
    make_response,
)
from datetime import datetime
import db

app = Flask(__name__)


[redacted secret-like line]

# Initialise database on startup
db.init_db()


# ── Context processor ──────────────────────────────────────────────
@app.context_processor
def inject_now():
    return {"now": datetime.utcnow()}


# ── Routes ─────────────────────────────────────────────────────────

@app.route("/")
def index():
    applications, total_apps = db.get_applications(page=1, per_page=100)
    targets = db.get_targets()
    stats = {
        "monthly_cost": "~$308",
        "funding_status": "Self-funded",
        "applications_sent": total_apps,
        "automation_level": "Mixed cadence",
        "funding_for": "Reach & People",
        "sites_live": 19,
    }
    return render_template("index.html", stats=stats)


@app.route("/costs")
def costs():
    return render_template("costs.html")


@app.route("/applications")
def applications():
    page = request.args.get("page", 1, type=int)
    per_page = 20
    rows, total = db.get_applications(page=page, per_page=per_page)
    total_pages = max(1, (total + per_page - 1) // per_page)
    return render_template(
        "applications.html",
        applications=rows,
        page=page,
        total_pages=total_pages,
        total=total,
    )


@app.route("/targets")
def targets():
    rows = db.get_targets()
    return render_template("targets.html", targets=rows)


@app.route("/sample")
def sample():
    return render_template("sample.html")


@app.route("/suggest", methods=["GET", "POST"])
def suggest():
    if request.method == "POST":
        organisation = request.form.get("organisation", "").strip()
        url = request.form.get("url", "").strip()
        relevance = request.form.get("relevance", "").strip()
        email = request.form.get("email", "").strip()

        if not organisation or not relevance:
            flash("Organisation name and relevance are required.", "error")
        else:
            db.add_suggestion(organisation, url, relevance, email or None)
            flash("Thank you! Your suggestion has been submitted for review.", "success")
            return redirect(url_for("suggest"))

    approved = db.get_approved_suggestions()
    return render_template("suggest.html", suggestions=approved)


@app.route("/about")
def about():
    return render_template("about.html")


# ── SEO ────────────────────────────────────────────────────────────

@app.route("/sitemap.xml")
def sitemap():
    pages = [
        {"loc": "https://funding.copecheck.com/", "priority": "1.0"},
        {"loc": "https://funding.copecheck.com/costs", "priority": "0.8"},
        {"loc": "https://funding.copecheck.com/applications", "priority": "0.8"},
        {"loc": "https://funding.copecheck.com/targets", "priority": "0.8"},
        {"loc": "https://funding.copecheck.com/sample", "priority": "0.7"},
        {"loc": "https://funding.copecheck.com/suggest", "priority": "0.6"},
        {"loc": "https://funding.copecheck.com/about", "priority": "0.5"},
    ]
    xml = '<?xml version="1.0" encoding="UTF-8"?>\n'
    xml += '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n'
    for p in pages:
        xml += "  <url>\n"
        xml += f'    <loc>{p["loc"]}</loc>\n'
        xml += f'    <priority>{p["priority"]}</priority>\n'
        xml += "  </url>\n"
    xml += "</urlset>"
    resp = make_response(xml)
    resp.headers["Content-Type"] = "application/xml"
    return resp


@app.route("/robots.txt")
def robots():
    txt = "User-agent: *\nAllow: /\nSitemap: https://funding.copecheck.com/sitemap.xml\n"
    resp = make_response(txt)
    resp.headers["Content-Type"] = "text/plain"
    return resp


# ── Health check ───────────────────────────────────────────────────

@app.route("/health")
def health():
    return {"status": "ok", "service": "copecheck-funding"}, 200


@app.route("/ai-disclosure")
def ai_disclosure():
    return render_template("ai_disclosure.html")


if __name__ == "__main__":
    app.run(host="0.0.0.0", port=5010, debug=True)


# ── Trailing-slash canonicalisation (added 2026-09-26, infra audit) ──
# Flask 404s on "/foo/" when the route is declared as "/foo". This installs a
# before_request hook that 301s the slashed form to the canonical slash-less
# one, but only when the slashed form is not itself a real route. Revert by
# deleting these three lines and slash_canonical.py.
from slash_canonical import install_slash_canonicaliser  # noqa: E402
install_slash_canonicaliser(app)  # noqa: E402
```
