ImportError:无法在django应用程序中导入名称模式
我正在尝试为我的研究创建一个Facebook提取器。为了这个目的我尝试了很多库,但是找不到一个例子。最后我已经达到了这个repository,我猜是我在找的东西。ImportError:无法在django应用程序中导入名称模式
但问题是,当我跑了,我凸轮跨以下错误E:
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.5
和Python 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月17日2015年
看到这种情况,我相信,该项目不建使用Django1.11.5 。
你应该通过安装Django1.8这样的老版本的django来进行检查。
如果我想使用当前版本,那么是否有解决方案? –
如果你能够在最新版本下解决这个问题,那么你可能会再次陷入其他地方。我建议你要么使用Django 1.8,要么使用Django从头开始编写完整的项目1.11 –
您应该将您的Django版本降级到1.8(例如),因为模式在高版本中被删除。
我可以知道如果这不适用于1.11,那么1.11中有什么相同的内容? –
请查看https://github.com/davittomasso/psa-allauth。 –
但我建议从头开始写。 –
从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': '/'}),
. . . . . .
. . . . . .
]
Update after comment:
您需要为更新的Django:
pip install django
@JafferWilson,我希望这对你有意义。我也早一点面对同样的问题。 –
我想你还没有看到我的问题的最后一行。我已经尝试过了。 'File'C:\ Python27 \ lib \ site-packages \ django \ conf \ urls \ __ init__.py“,第85行,在url中 raise TypeError('view必须是可调用的或列表/元组()。') TypeError:在include()的情况下,视图必须是可调用的或列表/元组。' –
@JafferWilson,尝试获取最新版本的django。这个问题是版本的问题。 –
尝试安装模式
pip install patterns
然后尝试你的代码。
我不认为我的代码中的模式与'patterns'库有关。我仍然会检查。 –
导入错误是[此问题]的重复(https://*.com/questions/38786036/importerror-cannot-import-name-patterns)。一旦你删除了导入,'视图必须是可调用的或者列表/元组'错误是[this one]的重复(https://*.com/questions/38744285/django-urls-error-view - 必须是可调用的或列表中的元组) – Alasdair