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

Django 1.11安装django-facebook6.0.3遇ImportError问题求助

Fixing ImportError: No module named 'django.conf.urls.defaults' with django-facebook 6.0.3 and Django 1.11

Hey there, let's break down why this error is happening and how to fix it properly.

Why the Error Occurs

Django removed the django.conf.urls.defaults module starting from version 1.8, moving url and patterns directly into django.conf.urls. The django-facebook 6.0.3 package is outdated and still references the old module path, which is why you're hitting this import error.

Your existing try-except code didn't work because you added it to your own project files, but the error is coming from the third-party django-facebook package's urls.py file—so your code doesn't affect that file at all.

Solution 1: Manually Patch the django-facebook urls.py File

This is the most straightforward fix for this specific error:

  1. Navigate to the file mentioned in the error: path/lib/python3.5/site-packages/django_facebook/urls.py
  2. Replace the line:
    from django.conf.urls.defaults import patterns, url
    
    With:
    from django.conf.urls import url
    # We'll handle the `patterns` function next
    
  3. Look for any uses of patterns('', ...) in the file and convert them to a list of url() objects. For example:
    • Old code (using deprecated patterns):
      urlpatterns = patterns('',
          url(r'^login/$', ...),
          # more URL definitions
      )
      
    • Updated code (compatible with Django 1.11+):
      urlpatterns = [
          url(r'^login/$', ...),
          # more URL definitions
      ]
      
    Django 1.11 still supports patterns but throws deprecation warnings, so converting to a list is cleaner and avoids future issues.

Solution 2: Monkey Patching (Temporary Workaround)

If you don't want to modify third-party package files directly, you can add a monkey patch to your project's settings.py to trick django-facebook into finding the module:

# Add this at the TOP of your settings.py
import django.conf.urls
import sys

# Create a dummy module that mirrors the old defaults structure
sys.modules['django.conf.urls.defaults'] = django.conf.urls

This will make the import from django.conf.urls.defaults import ... point to the current django.conf.urls module. Note that this is a temporary band-aid—you might still run into other compatibility problems with the outdated django-facebook package.

Long-Term Recommendation

django-facebook 6.0.3 is quite old and likely unmaintained. You'll probably run into more compatibility issues with Django 1.11 down the line. Consider switching to an actively maintained package like django-allauth for Facebook authentication—it supports modern Django versions and handles OAuth flows more reliably.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.28 09:35:00