
言語 🇯🇵 日本語
ドキュメント
はじめに
使用
API リファレンス
Django アプリにコメントを追加する
これは FastComments の公式 Django パッケージです。
テンプレートタグを使用した安全な SSO を備えたライブコメントおよびチャットコンポーネントです。
Repository
要件 
- Python 3.10+
- Django 4.2、5.0、5.1、または5.2
- FastComments のテナント ID(
demoを使用してアカウントなしで試す) - Secure SSO のみ、API secret が必要です
インストール 
Install from a release tag (this project is distributed via git tags, not PyPI):
pip install "git+https://github.com/fastcomments/fastcomments-django.git@v0.1.0"
For server-side REST access (the admin() / public_api() helpers), add the
api extra, which pulls in the SDK's generated client:
pip install "fastcomments-django[api] @ git+https://github.com/fastcomments/fastcomments-django.git@v0.1.0"
Add the app to INSTALLED_APPS:
INSTALLED_APPS = [
# ...
"fastcomments_django",
]
クイックスタート 
settings.pyでテナントを構成します:
import os
FASTCOMMENTS = {
"TENANT_ID": os.environ.get("FASTCOMMENTS_TENANT_ID", "demo"),
}
任意のテンプレートにウィジェットを配置します:
{% load fastcomments %}
{% fastcomments url_id="my-page" %}
自動シングルサインオンの前提条件 
To pass the logged-in user to the widget automatically, the tags read the current user from the request. Make sure your project has both of these (they are on by default in a standard Django project):
django.template.context_processors.requestinTEMPLATES["OPTIONS"]["context_processors"]django.contrib.auth.middleware.AuthenticationMiddlewareinMIDDLEWARE
Without a request in the template context, widgets render for an anonymous
visitor. You can always pass a user explicitly: {% fastcomments user=some_user %}.
ウィジェットタグ 
Every widget has its own tag. All of them accept **extra keyword arguments,
which are merged into the widget config as-is (use camelCase keys) for anything
not covered by the named arguments below.
| タグ | ウィジェット |
|---|---|
{% fastcomments %} | Comments |
{% fastcomments_live_chat %} | Live chat |
{% fastcomments_comment_count %} | Comment count badge |
{% fastcomments_comment_count_bulk %} + {% fastcomments_count_marker %} | Bulk comment counts |
{% fastcomments_collab_chat target="#el" %} | Collaborative (inline) chat |
{% fastcomments_image_chat target="#el" %} | Image annotation chat |
{% fastcomments_recent_comments %} | Recent comments |
{% fastcomments_recent_discussions %} | Recent discussions |
{% fastcomments_reviews_summary %} | Reviews summary |
{% fastcomments_top_pages %} | Most-discussed pages |
{% fastcomments_user_activity user_id="..." %} | A user's activity feed |
Named arguments map to the widget's camelCase config keys:
| 引数 | 設定キー | タグ |
|---|---|---|
url_id | urlId | comments, live chat, comment count, collab/image chat, recent comments, reviews summary |
url | url | comments, live chat, collab/image chat |
readonly | readonly | comments, live chat, collab/image chat |
locale | locale | comments, live chat, collab/image chat, user activity |
has_dark_background | hasDarkBackground | all |
default_sort_direction | defaultSortDirection | comments, live chat, collab/image chat |
number_only | numberOnly | comment count |
is_live | isLive | comment count |
count | count | recent comments, recent discussions |
target | (querySelector, not sent) | collab chat, image chat |
chat_square_percentage | chatSquarePercentage | image chat |
user_id | userId | user activity |
Examples:
{% load fastcomments %}
{% fastcomments url_id="my-page" locale="en_us" default_sort_direction="MR" %}
{% fastcomments_live_chat url_id="room-1" %}
Comments: {% fastcomments_comment_count url_id="my-page" number_only=True %}
{# Collab chat attaches to an existing element on the page #}
<article id="post-body">...</article>
{% fastcomments_collab_chat target="#post-body" %}
{# Bulk counts: place markers, then one bulk loader fills them all in #}
{% 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(シングルサインオン) 
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"], # あなたのAPIシークレット; Secure SSOに署名します
"SSO": {
"ENABLED": True,
"MODE": "secure", # "secure" | "simple"
# FastComments のフィールドをユーザーモデルにマップします。値は属性
# 名、ドット区切りパス("profile.avatar_url")、callable(user)、または None です。
"USER_MAP": {
"id": "id",
"email": "email",
"username": "username",
"avatar": None,
"display_name": None,
"website_url": None,
},
"IS_ADMIN": lambda user: user.is_staff, # callable(user) -> bool、またはドット区切りパス
"IS_MODERATOR": None,
"GROUP_IDS": None, # callable(user) -> list、またはドット区切りパス
},
}
SSO の
idを慎重に選択してください。 FastComments のidはユーザーのコメント履歴の永続的なハンドルです。デフォルトのUSER_MAPは設定不要の便利さのためにあなたの Django の主キーにマップしますが、連続した整数 PK は列挙可能で後で変更が困難です(ユーザーのidを変更すると履歴が新しいアカウントに分割されます)。デモを超えるすべての場合、idを事前に選択した安定した不透明な値(UUID または専用の公開 ID)にマップし、決してプライベートデータを格納しないでください。この理由でサンプルアプリはユーザー名ベースの id を使用しています。
SSO は現在のユーザーに対して {% fastcomments %}, {% fastcomments_live_chat %},
{% fastcomments_collab_chat %}, {% fastcomments_image_chat %}, および
{% fastcomments_user_activity %} に自動的に注入されます。
Login/logout URLs shown to signed-out visitors default to reverse("login") /
reverse("logout"); override them with SSO["LOGIN_URL"] / SSO["LOGOUT_URL"].
カスタムマッピング
USER_MAP よりも優先度の高いオプションが2つあります:
-
ユーザーモデルのメソッド(インターフェースの Python的類似):
class User(AbstractUser): def to_fastcomments_user_data(self): return {"id": self.pk, "email": self.email, "username": self.get_username()} -
グローバルマッパー、
callable(user) -> dictへのドット区切りパス:FASTCOMMENTS = {"SSO": {"USER_MAPPER": "myapp.sso.map_user"}}
優先順位は USER_MAPPER > to_fastcomments_user_data() > USER_MAP です。
サーバーサイド API アクセス 
[api] エクストラがインストールされている状態で、SDK を通じて FastComments REST API を呼び出します。API キーとリージョンが事前に設定されています:
from fastcomments_django import admin, public_api, get_manager
admin().get_comments("YOUR_TENANT_ID", ...) # 認証済み (DefaultApi)
public_api().get_comments_public(...) # 公開 (PublicApi)
# API 呼び出しまたはクライアントハンドオフ用に SSO トークンを生成:
token = get_manager().sso().token_for(request.user)
EU リージョン 
REGION を設定して、ウィジェットと API を EU にルーティングします:
FASTCOMMENTS = {"TENANT_ID": "...", "REGION": "eu"}
埋め込みマークアップのカスタマイズ 
fastcomments/widget.html を、テンプレート検索パスの上位に自分のコピーを早めに配置することで上書きします
テンプレート検索パス(プロジェクトの templates/fastcomments/widget.html)。これは
Laravel の vendor:publish --tag=fastcomments-views に相当する Django のアナログです。
設定リファレンス 
| キー | デフォルト | 説明 |
|---|---|---|
TENANT_ID | "" | FastComments のテナント ID (demo はテスト用)。 |
API_KEY | "" | API シークレット。Secure SSO に署名し、admin() を認証します。 |
REGION | None | None は米国、"eu" は EU リージョンです。 |
SSO.ENABLED | False | SSO をオンにします。 |
SSO.MODE | "secure" | "secure" (HMAC) または "simple" (無署名)。 |
SSO.LOGIN_URL / SSO.LOGOUT_URL | None | サインアウトした訪問者に表示されます。デフォルトは reverse("login"/"logout") です。 |
SSO.USER_MAP | id/email/username | FastComments のフィールドをユーザー属性/パス/呼び出し可能オブジェクトにマッピングします。 |
SSO.IS_ADMIN / IS_MODERATOR / GROUP_IDS | None | callable(user) またはドット区切りパス。 |
SSO.USER_MAPPER | None | callable(user) -> dict へのドット区切りパス。最も高い優先度です。 |
WIDGET_DEFAULTS | {} | すべてのウィジェットにマージされる設定(camelCase キー)。 |
サンプルプロジェクト 
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
# Secure SSO を実際に見るために自分のテナントを使用してください(API シークレットが必要です):
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。
助けが必要ですか?
Django パッケージに関して問題が発生したり質問がある場合は、以下をご利用ください:
貢献
貢献は歓迎します!貢献ガイドラインについては、GitHub リポジトリをご覧ください。