Django'ImportError:无法导入名称url'

时间:2019-04-06 02:13:38

标签: django

您好,有人可以帮助我解决“ ImportError:无法导入名称网址”问题吗? 我在这里https://docs.djangoproject.com/en/1.9/intro/tutorial01/

遵循了教程

我尝试了另一本教程https://docs.djangoproject.com/zh-hans/2.0/ref/urls/#django.urls.include 但是他们两个都不起作用 我的Django版本是1.11.20

  

执行系统检查...
  由Traceback启动的线程中未处理的异常   (最近通话过去):
  文件   “ /usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py”,   第228行,在包装程序fn(* args,** kwargs)中
  文件   “ /usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py”,   第124行,inner_run self.check(display_num_errors = True)
  文件   “ /usr/local/lib/python2.7/dist-packages/django/core/management/base.py”,   359行,在支票中
  include_deployment_checks =包含_deployment_checks,
  文件   “ /usr/local/lib/python2.7/dist-packages/django/core/management/base.py”,   第346行,_run_checks返回   check.run_checks(** kwargs)
  文件   “ /usr/local/lib/python2.7/dist-packages/django/core/checks/registry.py”,   第81行,在run_checks new_errors =   检查(app_configs = app_configs)
  文件   “ /usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py”,   第16行,在check_url_config中返回   check_resolver(解析器)
  文件   “ /usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py”,   第26行,在check_resolver中返回check_method()   文件   “ /usr/local/lib/python2.7/dist-packages/django/urls/resolvers.py”,   第256行,检查模式   self.url_patterns:
  文件   “ /usr/local/lib/python2.7/dist-packages/django/utils/functional.py”,   第35行,获取中,res =   实例。 dict [self.name] = self.func(instance)
  文件   “ /usr/local/lib/python2.7/dist-packages/django/urls/resolvers.py”,   第407行,采用url_patterns模式=   getattr(self.urlconf_module,“ urlpatterns”,self.urlconf_module)
  文件   “ /usr/local/lib/python2.7/dist-packages/django/utils/functional.py”,   第35行,获取中,res =   实例。 dict [self.name] = self.func(instance)
  文件   “ /usr/local/lib/python2.7/dist-packages/django/urls/resolvers.py”,   第400行,在urlconf_module中返回   import_module(self.urlconf_name)
  在第37行的“ /usr/lib/python2.7/importlib/init.py”文件中   import_module
  导入(名称)文件“ /home/adduser/cantera_correction/mysite/urls.py”,第16行                                                 从   django.conf.urls导入包括路径
  ImportError:无法导入名称路径

2 个答案:

答案 0 :(得分:1)

更正您的导入:

from django.urls import path, include

答案 1 :(得分:0)

path was introduced in django since Django 2.0。因此,如果您使用的是Django 1.11,则无法使用它。您需要像这样定义urls

from django.conf.urls import url, include

urlpatterns = [
    # rest of the urls
    url(r'^$', HomeView.as_view()),

]