3
votes

Hi could anyone help me fix 'ImportError: cannot import name url' problem? I have followed tutorial here https://docs.djangoproject.com/en/1.9/intro/tutorial01/

I have tried another tutorial https://docs.djangoproject.com/zh-hans/2.0/ref/urls/#django.urls.include but neither of them worked My Django version is 1.11.20

Performing system checks...
Unhandled exception in thread started by Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 228, in wrapper fn(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 124, in inner_run self.check(display_num_errors=True)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 359, in check
include_deployment_checks=include_deployment_checks,
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 346, in _run_checks return checks.run_checks(**kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/core/checks/registry.py", line 81, in run_checks new_errors = check(app_configs=app_configs)
File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 16, in check_url_config return check_resolver(resolver)
File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 26, in check_resolver return check_method() File "/usr/local/lib/python2.7/dist-packages/django/urls/resolvers.py", line 256, in check for pattern in self.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 35, in get res = instance.dict[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/dist-packages/django/urls/resolvers.py", line 407, in url_patterns patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 35, in get res = instance.dict[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/dist-packages/django/urls/resolvers.py", line 400, in urlconf_module return import_module(self.urlconf_name)
File "/usr/lib/python2.7/importlib/init.py", line 37, in import_module
import(name) File "/home/adduser/cantera_correction/mysite/urls.py", line 16, in from django.conf.urls import include, path
ImportError: cannot import name path

2
Were gonna need a bit more information, such as a full error stack trace, as well as maybe your urls.pyHybrid

2 Answers

5
votes

path was introduced in django since Django 2.0. So, if you are using Django 1.11, then you can't use it. You need to define urls like this:

from django.conf.urls import url, include

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

]
1
votes

correct your imports to this:

from django.urls import path, include