运行 python3 manage.py 迁移时 Virtualenv(Python3.5/pip3/Django2.0/psycopg2) 出错

Error in Virtualenv(Python3.5/pip3/Django2.0/psycopg2) when run python3 manage.py migrate

我可以 运行 manage.py 迁移到 Virtualenv(Python3.5/pip3/Django2.0/psycopg2)。

(miWeb) xxxx@yyyy:~/myproject/miWeb$ python3 manage.py migrate
/home/xxxx/mipagina/lib/python3.5/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
  """)
Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "/home/xxxx/miWeb/lib/python3.5/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "/home/xxxx/miWeb/lib/python3.5/site-packages/django/core/management/__init__.py", line 365, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/xxxx/miWeb/lib/python3.5/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/xxxx/miWeb/lib/python3.5/site-packages/django/core/management/base.py", line 332, in execute
    self.check()
  File "/home/xxxx/miWeb/lib/python3.5/site-packages/django/core/management/base.py", line 364, in check
    include_deployment_checks=include_deployment_checks,
  File "/home/xxxx/miWeb/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 58, in _run_checks
    issues.extend(super()._run_checks(**kwargs))
  File "/home/xxxx/miWeb/lib/python3.5/site-packages/django/core/management/base.py", line 351, in _run_checks
    return checks.run_checks(**kwargs)
  File "/home/xxxx/miWeb/lib/python3.5/site-packages/django/core/checks/registry.py", line 73, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/home/xxxx/miWeb/lib/python3.5/site-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique
    all_namespaces = _load_all_namespaces(resolver)
  File "/home/xxxx/miWeb/lib/python3.5/site-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces
    url_patterns = getattr(resolver, 'url_patterns', [])
  File "/home/xxxx/miWeb/lib/python3.5/site-packages/django/utils/functional.py", line 36, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/xxxx/miWeb/lib/python3.5/site-packages/django/urls/resolvers.py", line 536, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/home/xxxx/miWeb/lib/python3.5/site-packages/django/utils/functional.py", line 36, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/xxxx/miWeb/lib/python3.5/site-packages/django/urls/resolvers.py", line 529, in urlconf_module
    return import_module(self.urlconf_name)
  File "/home/xxxx/miWeb/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/xxxx/myproject/miWeb/miWeb/urls.py", line 20, in <module>
    path('admin/', admin.site.urls),
NameError: name 'path' is not defined
(miWeb) xxxx@yyyy:~/myproject/miWeb$ 

我正在学习 django,所以我打算做我的第一个 django 项目,所以我按照一些简单的默认步骤首先创建一个环境,然后简单地制作一个 "manage.py migrate" 命令。

我不知道我必须在 urls.py 文件的第 20 行中更改什么:

"""miWeb URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.0/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import include, re_path

urlpatterns = [
    path('admin/', admin.site.urls),
]

path and re_path 都是 django.urls.

中的不同模块

您正在导入 re_path 并使用 path

将代码更改为

from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    path('admin/', admin.site.urls),
]

如果您想同时使用 pathre_path,请导入两者。

from django.urls import include, path, re_path