Django的BUG:ImportError: cannot import name 'patterns'
生活随笔
收集整理的這篇文章主要介紹了
Django的BUG:ImportError: cannot import name 'patterns'
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
在學(xué)習(xí)Docker容器與容器云第2版時出現(xiàn)的BUG:
第二章,搭建第一個Hello World程序,運行:
時報錯:
Traceback (most recent call last):File "manage.py", line 22, in <module>execute_from_command_line(sys.argv)File "/usr/local/lib/python3.4/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_lineutility.execute()File "/usr/local/lib/python3.4/site-packages/django/core/management/__init__.py", line 359, in executeself.fetch_command(subcommand).run_from_argv(self.argv)File "/usr/local/lib/python3.4/site-packages/django/core/management/base.py", line 294, in run_from_argvself.execute(*args, **cmd_options)File "/usr/local/lib/python3.4/site-packages/django/core/management/base.py", line 342, in executeself.check()File "/usr/local/lib/python3.4/site-packages/django/core/management/base.py", line 374, in checkinclude_deployment_checks=include_deployment_checks,File "/usr/local/lib/python3.4/site-packages/django/core/management/base.py", line 361, in _run_checksreturn checks.run_checks(**kwargs)File "/usr/local/lib/python3.4/site-packages/django/core/checks/registry.py", line 81, in run_checksnew_errors = check(app_configs=app_configs)File "/usr/local/lib/python3.4/site-packages/django/core/checks/urls.py", line 14, in check_url_configreturn check_resolver(resolver)File "/usr/local/lib/python3.4/site-packages/django/core/checks/urls.py", line 24, in check_resolverfor pattern in resolver.url_patterns:File "/usr/local/lib/python3.4/site-packages/django/utils/functional.py", line 35, in __get__res = instance.__dict__[self.name] = self.func(instance)File "/usr/local/lib/python3.4/site-packages/django/urls/resolvers.py", line 313, in url_patternspatterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)File "/usr/local/lib/python3.4/site-packages/django/utils/functional.py", line 35, in __get__res = instance.__dict__[self.name] = self.func(instance)File "/usr/local/lib/python3.4/site-packages/django/urls/resolvers.py", line 306, in urlconf_modulereturn import_module(self.urlconf_name)File "/usr/local/lib/python3.4/importlib/__init__.py", line 109, in import_modulereturn _bootstrap._gcd_import(name[level:], package, level)File "<frozen importlib._bootstrap>", line 2254, in _gcd_importFile "<frozen importlib._bootstrap>", line 2237, in _find_and_loadFile "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlockedFile "<frozen importlib._bootstrap>", line 1200, in _load_unlockedFile "<frozen importlib._bootstrap>", line 1129, in _execFile "<frozen importlib._bootstrap>", line 1471, in exec_moduleFile "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removedFile "/usr/src/app/dockerweb/redisweb/redisweb/urls.py", line 16, in <module>from django.conf.urls import patterns,include,url ImportError: cannot import name 'patterns'錯誤原因:
從1.10后django后patterns被移除了,已經(jīng)沒有這個模塊了。使用 django 1.10 以后的版本需要改用 django.conf.urls.url() 。
錯誤代碼:
改正代碼:
from django.conf.urls import url,include from django.contrib import admin from helloworld.views import hellourlpatterns = [url(r'^admin/', include(admin.site.urls)),url(r'^helloworld$', hello), ]
運行效果:
總結(jié)
以上是生活随笔為你收集整理的Django的BUG:ImportError: cannot import name 'patterns'的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: sim3优化的理解
- 下一篇: 1、微信公众平台注册