如何解决Django站点部分页面Facebook评论不进审核工具的问题?
Hey there, let's dig into why some of your Django pages aren't showing comments in the Facebook moderation tool, even after fixing the appId parameter. Since the Sharing Debugger recognizes all meta tags correctly, the issue is likely tied to how comments are being associated with your app and page URLs.
1. Ensure data-href Matches og:url Exactly
This is the most common culprit for comment moderation mismatches. Facebook uses the page URL to map comments to your app, so if the data-href on your fb-comments component doesn't perfectly match the og:url meta tag, comments won't show up in your moderation dashboard.
Looking at your code:
- Your
og:urluses the{{ article_url }}variable - Your
fb-commentscomponent builds the URL withhttps://{{ SITE.domain }}{{ LURL }}{{ request.path_info }}
These two URLs need to be identical—same protocol (http/https), domain, path, query parameters, and even trailing slashes. For example, if article_url includes a language prefix but the data-href doesn't, or one has a trailing slash while the other doesn't, Facebook will treat them as separate pages.
Fix:
Update your fb-comments div to use the same article_url variable for consistency:
<div class="fb-comments" data-href="{{ article_url }}" data-num-posts="2" data-width="100%"></div>
Then, for problematic pages, copy both the rendered og:url and data-href values into the Sharing Debugger to confirm they're an exact match.
2. Check for Facebook Crawler Access Issues
Even if the Sharing Debugger shows your meta tags correctly, some pages might have barriers that prevent the Facebook crawler (facebookexternalhit/1.1) from properly indexing the page long-term. This can break comment association over time.
Things to verify:
- Your
robots.txtfile: Make sure it doesn't block the Facebook crawler. If you have aDisallowrule affecting these pages, add an exception forfacebookexternalhit/1.1. - Login walls or dynamic content: If pages require login to view, or load critical content via AJAX after initial page load, the crawler might not capture the full context. Ensure meta tags and the comment component are rendered server-side.
- Force a re-crawl: Use the "Scrape Again" button in the Sharing Debugger for problematic pages to refresh Facebook's cache of the page.
3. Fix Syntax Errors in the Facebook SDK Script
I noticed an orphaned {% endif %} in your SDK script:
js.src = "https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v6.0&appId={{ SOCIAL_AUTH_FACEBOOK_KEY }}&xbfml=true&autoLogAppEvents=1" {% endif %}
This template syntax error could cause the script to fail loading on some pages, preventing comments from linking to your app. Remove the {% endif %} since there's no corresponding {% if %} tag.
Also, verify that {{ SOCIAL_AUTH_FACEBOOK_KEY }} renders correctly on all pages. View the source of a problematic page and check that the appId in the SDK URL is your actual Facebook App ID (not an empty string or placeholder).
4. Verify SDK Initialization Order
While your code places the fb-root div before the fb-comments component (which is correct), other scripts on the page might interfere with the Facebook SDK. Check your browser's console for any JavaScript errors related to the SDK—these could point to initialization issues.
If you're dynamically loading the comment component (e.g., via AJAX), you'll need to call FB.XFBML.parse() after the component is added to the DOM to initialize it properly. Since you're using a static template, this is probably not the issue, but it's worth checking.
Final Testing Steps
After making these changes:
- Use the Sharing Debugger to re-scrape problematic pages and confirm all meta tags and appId are correctly detected.
- Post a test comment on each page.
- Check your Facebook Moderation Tool to see if the test comments appear.
内容的提问来源于stack exchange,提问作者Ahmad Afiquddin Ahmad

