简体   繁体   中英

ImportError: cannot import name patterns in django application

I am trying to create a facebook extractor for my research. for the purpose I have tried many libraries, but could not find an example. lastly I have reached this repository , which I guess is what I was looking for.

But the problem is when I ran the it, I cam e across the following error:

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

I am quite puzzled by this error, as I am encountering it for the first time. Tell me what I can do to improve the code? I m using Django 1.11.5 and Python 2.7.2 . Also there are no examples for Django 1.11.5 related to social authentication, so can anyone help me with that. It will be a great help. If I remove the pattern I get the following error:

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().

The given project was last updated on 17 Mar 2015.

Seeing this, I am sure that the project was not build using Django1.11.5.

You should check by installing some older django version like Django1.8.

From 1.8+ onwards patterns is removed and now In current version simply write like below, it will work fine.

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:

You need to update django for that:

pip install django

Try to install patterns

pip install patterns

then try your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM