You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Django集成Facebook注册报错:域名未包含在应用域名中

Fixing "Can't load URL" Error for Facebook Login in Django

Hey friend, let's walk through fixing this common Facebook OAuth error you're hitting with your Django app. The issue usually boils down to missing or incorrect settings in the Facebook Developer Portal—not just the App Domains you already configured. Here's what to check step by step:

1. Double-Check Valid OAuth Redirect URIs (Most Likely Culprit)

This is the setting people often overlook. Facebook needs to know exactly where to send users after they authenticate, and the URL has to match your Django app's callback path perfectly.

  • Go to your Facebook App Dashboard → Products → Facebook Login → Settings
  • In the Valid OAuth Redirect URIs field, add your full Django callback URL. For example, if you're using django-allauth (the most common package for social logins in Django), the URL is usually:
    http://127.0.0.1:8000/user/complete/facebook/
    
    If you built a custom callback system, use that exact full URL (include http://, the IP address, port number, and full path).
  • Don't forget to save changes after adding the URI.

2. Verify App Domains Setup

You already set this to 127.0.0.1, but let's confirm it's in the right place and formatted correctly:

  • Go to App Settings → Basic
  • Ensure the App Domains field has just 127.0.0.1 (no http://, no port number)
  • Save these settings if you made any adjustments.

3. Match Django's Callback URL to Facebook's Settings

If you're using django-allauth, double-check your settings.py to ensure the redirect URI matches what you entered in Facebook:

SOCIALACCOUNT_PROVIDERS = {
    'facebook': {
        'METHOD': 'oauth2',
        'SCOPE': ['email', 'public_profile'],
        # Add other necessary configs here
        'REDIRECT_URI': 'http://127.0.0.1:8000/user/complete/facebook/'
    }
}

If you have a custom view handling the callback, make sure its URL pattern exactly matches the one you added to Facebook's redirect URIs list.

4. Quick Final Checks

  • If you're testing with non-test users, ensure your Facebook app isn't stuck in "In Development" mode (though domain errors still occur in development mode, this can resolve related access issues).
  • Clear your browser cache and cookies, then retry the login flow—sometimes old cached OAuth data causes unexpected mismatches.

After updating these settings, the error should disappear, and users can successfully authenticate via Facebook on your local Django server.

内容的提问来源于stack exchange,提问作者Luqman Tuke

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 09:02:26