ImportError:无法在django应用程序中导入名称模式

时间:2017-10-07 11:37:31

标签: python django facebook facebook-graph-api

我正在尝试为我的研究创建一个facebook提取器。为了这个目的,我尝试了很多库,但找不到一个例子。最后我达到了这个repository,我想这就是我要找的东西。

但问题是当我运行它时,我发现了以下错误:

Performing system checks...

Unhandled exception in thread started by <function wrapper at 0x0000000004540518>
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\django\utils\autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "C:\Python27\lib\site-packages\django\core\management\commands\runserver.py", line 125, in inner_run
    self.check(display_num_errors=True)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 359, in check
    include_deployment_checks=include_deployment_checks,
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 346, in _run_checks
    return checks.run_checks(**kwargs)
  File "C:\Python27\lib\site-packages\django\core\checks\registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
  File "C:\Python27\lib\site-packages\django\core\checks\urls.py", line 16, in check_url_config
    return check_resolver(resolver)
  File "C:\Python27\lib\site-packages\django\core\checks\urls.py", line 26, in check_resolver
    return check_method()
  File "C:\Python27\lib\site-packages\django\urls\resolvers.py", line 254, in check
    for pattern in self.url_patterns:
  File "C:\Python27\lib\site-packages\django\utils\functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Python27\lib\site-packages\django\urls\resolvers.py", line 405, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "C:\Python27\lib\site-packages\django\utils\functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Python27\lib\site-packages\django\urls\resolvers.py", line 398, in urlconf_module
    return import_module(self.urlconf_name)
  File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
    __import__(name)
  File "C:\Users\lenovo-pc\Desktop\psa-allauth-master\example\urls.py", line 1, in <module>
    from django.conf.urls import patterns, include, url
ImportError: cannot import name patterns

我对这个错误感到非常困惑,因为我第一次遇到这个错误。告诉我我可以做些什么来改进代码?我正在使用Django 1.11.5Python 2.7.2。此外,没有与Django 1.11.5相关的社交身份验证示例,因此任何人都可以帮助我。这将是一个很大的帮助。 如果我删除pattern,我会收到以下错误:

File "C:\Python27\lib\site-packages\django\conf\urls\__init__.py", line 85, in url
    raise TypeError('view must be a callable or a list/tuple in the case of include().')
TypeError: view must be a callable or a list/tuple in the case of include().

3 个答案:

答案 0 :(得分:0)

该项目于2015年3月17日更新。

看到这一点,我确信该项目不是使用Django1.11.5构建的。

你应该通过安装一些像Django1.8这样的旧版django来检查。

答案 1 :(得分:0)

1.8+开始模式被移除,现在在当前版本中,只需按照下面的说明编写,它就可以正常工作。

from django.conf.urls import include, url

urlpatterns = [
    url(r'^$', 'example.app.views.home', name='home'),
    url(r'^logout/$', 'django.contrib.auth.views.logout', name='logout' kwargs={'next_page': '/'}),
    . . . . . . 
    . . . . . .
]
  

评论后更新:

您需要更新django:

pip install django

答案 2 :(得分:0)

尝试安装模式

pip install patterns

然后尝试你的代码。