
Sprache 🇩🇪 Deutsch
Dokumentation
Erste Schritte
Verwendung
API-Referenz
Kommentare zu Ihrer Django-App hinzufügen
Dies ist das offizielle Django-Paket für FastComments.
Live‑Kommentare und Chat‑Komponenten mit Secure SSO über Template‑Tags.
Repository
Anforderungen 
- Python 3.10+
- Django 4.2, 5.0, 5.1, or 5.2
- Eine FastComments-Mandanten-ID (verwenden Sie
demo, um es ohne Konto auszuprobieren) - Ein API‑Geheimnis ist nur für Secure SSO erforderlich
Installation 
Von einem Release‑Tag installieren (dieses Projekt wird über Git‑Tags verteilt, nicht über PyPI):
pip install "git+https://github.com/fastcomments/fastcomments-django.git@v0.1.0"
Für serverseitigen REST‑Zugriff (die admin() / public_api() Hilfsfunktionen), füge das
api‑Extra hinzu, das den vom SDK generierten Client einbindet:
pip install "fastcomments-django[api] @ git+https://github.com/fastcomments/fastcomments-django.git@v0.1.0"
Füge die App zu INSTALLED_APPS hinzu:
INSTALLED_APPS = [
# ...
"fastcomments_django",
]
Schnellstart 
Konfigurieren Sie Ihren Mandanten in settings.py:
import os
FASTCOMMENTS = {
"TENANT_ID": os.environ.get("FASTCOMMENTS_TENANT_ID", "demo"),
}
Fügen Sie das Widget in jede Vorlage ein:
{% load fastcomments %}
{% fastcomments url_id="my-page" %}
Voraussetzungen für automatisches SSO 
Um den angemeldeten Benutzer automatisch an das Widget zu übergeben, lesen die Tags den
aktuellen Benutzer aus der Anfrage. Stellen Sie sicher, dass Ihr Projekt beide dieser (sie
standardmäßig in einem Standard‑Django‑Projekt aktiviert) Komponenten enthält:
django.template.context_processors.requestinTEMPLATES["OPTIONS"]["context_processors"]django.contrib.auth.middleware.AuthenticationMiddlewareinMIDDLEWARE
Ohne eine Anfrage im Template-Kontext rendern Widgets für einen anonymen
Besucher. Sie können immer explizit einen Benutzer übergeben: {% fastcomments user=some_user %}.
Widget-Tags 
Jedes Widget hat sein eigenes Tag. Alle akzeptieren das Schlüsselwort‑Argument **extra, das unverändert (mit camelCase‑Schlüsseln) in die Widget‑Konfiguration übernommen wird, wenn es nicht von den unten genannten benannten Argumenten abgedeckt wird.
| Tag | Widget |
|---|---|
{% fastcomments %} | Kommentare |
{% fastcomments_live_chat %} | Live‑Chat |
{% fastcomments_comment_count %} | Kommentar‑Zähler‑Badge |
{% fastcomments_comment_count_bulk %} + {% fastcomments_count_marker %} | Bulk‑Kommentarzähler |
{% fastcomments_collab_chat target="#el" %} | Kollaborativer (inline) Chat |
{% fastcomments_image_chat target="#el" %} | Bild‑Annotierungs‑Chat |
{% fastcomments_recent_comments %} | Aktuelle Kommentare |
{% fastcomments_recent_discussions %} | Aktuelle Diskussionen |
{% fastcomments_reviews_summary %} | Zusammenfassung von Bewertungen |
{% fastcomments_top_pages %} | Meist‑diskutierte Seiten |
{% fastcomments_user_activity user_id="..." %} | Aktivitäts‑Feed eines Benutzers |
Benannte Argumente entsprechen den camelCase‑Konfigurationsschlüsseln des Widgets:
| Argument | Konfigurationsschlüssel | Tags |
|---|---|---|
url_id | urlId | Kommentare, Live‑Chat, Kommentar‑Zähler, Kollaborativer/Bild‑Chat, aktuelle Kommentare, Zusammenfassung von Bewertungen |
url | url | Kommentare, Live‑Chat, Kollaborativer/Bild‑Chat |
readonly | readonly | Kommentare, Live‑Chat, Kollaborativer/Bild‑Chat |
locale | locale | Kommentare, Live‑Chat, Kollaborativer/Bild‑Chat, Benutzer‑Aktivität |
has_dark_background | hasDarkBackground | alle |
default_sort_direction | defaultSortDirection | Kommentare, Live‑Chat, Kollaborativer/Bild‑Chat |
number_only | numberOnly | Kommentar‑Zähler |
is_live | isLive | Kommentar‑Zähler |
count | count | aktuelle Kommentare, aktuelle Diskussionen |
target | (querySelector, nicht gesendet) | Kollaborativer Chat, Bild‑Chat |
chat_square_percentage | chatSquarePercentage | Bild‑Chat |
user_id | userId | Benutzer‑Aktivität |
Beispiele:
{% load fastcomments %}
{% fastcomments url_id="my-page" locale="en_us" default_sort_direction="MR" %}
{% fastcomments_live_chat url_id="room-1" %}
Kommentare: {% fastcomments_comment_count url_id="my-page" number_only=True %}
{# Kollaborativer Chat fügt sich an ein vorhandenes Element auf der Seite ein #}
<article id="post-body">...</article>
{% fastcomments_collab_chat target="#post-body" %}
{# Bulk‑Zähler: Marker setzen, dann füllt ein Bulk‑Loader sie alle aus #}
{% for post in posts %}
<a href="\{{ post.url }}">\{{ post.title }}</a>
{% fastcomments_count_marker url_id=post.url_id %}
{% endfor %}
{% fastcomments_comment_count_bulk %}
SSO (Single Sign-On) 
Enable SSO and choose a mode in settings.py. Secure SSO signs the user
server-side with HMAC-SHA256 using your API secret and is recommended.
FASTCOMMENTS = {
"TENANT_ID": os.environ["FASTCOMMENTS_TENANT_ID"],
"API_KEY": os.environ["FASTCOMMENTS_API_KEY"], # Ihr API-Geheimschlüssel; signiert Secure SSO
"SSO": {
"ENABLED": True,
"MODE": "secure", # "secure" | "simple"
# FastComments-Felder auf Ihr Benutzermodell abbilden. Werte können ein Attribut
# Name, ein Pfad mit Punkten ("profile.avatar_url"), ein aufrufbares(user) oder None.
"USER_MAP": {
"id": "id",
"email": "email",
"username": "username",
"avatar": None,
"display_name": None,
"website_url": None,
},
"IS_ADMIN": lambda user: user.is_staff, # aufrufbares(user) -> bool, oder Pfad mit Punkten
"IS_MODERATOR": None,
"GROUP_IDS": None, # aufrufbares(user) -> list, oder Pfad mit Punkten
},
}
Choose the SSO
iddeliberately. The FastCommentsidis the permanent handle for a user's comment history. The defaultUSER_MAPmaps it to your Django primary key for zero-config convenience, but sequential integer PKs are enumerable and hard to change later (changing a user'sidsplits their history into a new account). For anything beyond a demo, mapidto a stable, opaque value chosen up front (a UUID or a dedicated public id), and never put private data in it. The example app uses a username-based id for this reason.
SSO is injected automatically into {% fastcomments %}, {% fastcomments_live_chat %},
{% fastcomments_collab_chat %}, {% fastcomments_image_chat %}, and
{% fastcomments_user_activity %} for the current user.
Login/logout URLs shown to signed-out visitors default to reverse("login") /
reverse("logout"); override them with SSO["LOGIN_URL"] / SSO["LOGOUT_URL"].
Custom mapping
Two higher-precedence options beat USER_MAP:
-
Eine Methode in Ihrem Benutzermodell (die pythonische Analogie zu einem Interface):
class User(AbstractUser): def to_fastcomments_user_data(self): return {"id": self.pk, "email": self.email, "username": self.get_username()} -
Ein globaler Mapper, ein Pfad mit Punkten zu
callable(user) -> dict:FASTCOMMENTS = {"SSO": {"USER_MAPPER": "myapp.sso.map_user"}}
Precedence is USER_MAPPER > to_fastcomments_user_data() > USER_MAP.
Serverseitiger API-Zugriff 
Mit dem [api]‑Extra installiert, rufen Sie die FastComments REST API über das SDK auf, das mit Ihrem API‑Schlüssel und Ihrer Region vorkonfiguriert ist:
from fastcomments_django import admin, public_api, get_manager
admin().get_comments("YOUR_TENANT_ID", ...) # authentifiziert (DefaultApi)
public_api().get_comments_public(...) # öffentlich (PublicApi)
# Generieren Sie ein SSO‑Token für API‑Aufrufe oder die Weitergabe an den Client:
token = get_manager().sso().token_for(request.user)
EU-Region 
Setzen Sie REGION, um die Widgets und die API in die EU zu leiten:
FASTCOMMENTS = {"TENANT_ID": "...", "REGION": "eu"}
Anpassen des Einbettungs-Markups 
Überschreiben Sie fastcomments/widget.html, indem Sie Ihre eigene Kopie früher im
Vorlagensuchpfad (ein Projekt templates/fastcomments/widget.html). Dies ist
das Django-Analogon zu Laravels vendor:publish --tag=fastcomments-views.
Einstellungsreferenz 
| Key | Default | Description |
|---|---|---|
TENANT_ID | "" | Ihre FastComments Mandanten‑ID (demo für Tests). |
API_KEY | "" | Ihr API‑Geheimnis. Signiert Secure SSO und authentifiziert admin(). |
REGION | None | None für US, "eu" für die EU‑Region. |
SSO.ENABLED | False | SSO aktivieren. |
SSO.MODE | "secure" | "secure" (HMAC) oder "simple" (unsigned). |
SSO.LOGIN_URL / SSO.LOGOUT_URL | None | Wird abgemeldeten Besuchern angezeigt; standardmäßig reverse("login"/"logout"). |
SSO.USER_MAP | id/email/username | FastComments‑Feld zum Benutzerattribut/Pfad/Callable. |
SSO.IS_ADMIN / IS_MODERATOR / GROUP_IDS | None | callable(user) oder gepunkteter Pfad. |
SSO.USER_MAPPER | None | Gepunkteter Pfad zu callable(user) -> dict; höchste Priorität. |
WIDGET_DEFAULTS | {} | Konfiguration, die in jedes Widget (camelCase‑Schlüssel) zusammengeführt wird. |
Beispielprojekt 
A runnable showcase lives in example/: a left-rail + main-stage
app with a page per widget and a sign-in page listing pre-seeded demo users.
Sign in as any of them and the comment and live-chat widgets authenticate that
identity via Secure SSO. From that directory:
python manage.py migrate
# Use your own tenant to see Secure SSO in action (an API secret enables it):
FASTCOMMENTS_TENANT_ID=... FASTCOMMENTS_API_KEY=... python manage.py runserver
Without an API secret it falls back to the public demo tenant (anonymous).
example/browser_smoke.py is a Playwright e2e
that loads the page in a real browser and posts a comment as the Secure-SSO
user.
Benötigen Sie Hilfe?
Wenn Sie auf Probleme stoßen oder Fragen zum Django-Paket haben, bitte:
Mitwirken
Beiträge sind willkommen! Bitte besuchen Sie das GitHub-Repository für Richtlinien zum Mitwirken.