Python 导入错误:无法导入名称模式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38786036/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 21:25:22  来源:igfitidea点击:

ImportError: cannot import name patterns

pythondjango

提问by Alex

Python Version:2.7.5

Python 版本:2.7.5

Django Version:1.10

Django 版本:1.10

When I type nohup python manage.py runserver 0.0.0.0:9001it shows me

当我输入时nohup python manage.py runserver 0.0.0.0:9001它会显示我

enter image description here

在此处输入图片说明

I have googled and someone told me to vi urls.py, but it doesn't work. Another error occurred which shows that cannot import name default.

我用谷歌搜索,有人告诉我vi urls.py,但它不起作用。发生了另一个错误,表明cannot import name default.

回答by ger.s.brett

Use of patterns is deprecated since django 1.8. See docs. You can use plain lists now.

自 django 1.8 起不推荐使用模式。请参阅文档。您现在可以使用普通列表。

回答by user2947136

The use of patterns is deprecated in Django1.10. Therefore do not import 'patterns' and your url pattern should be as follows:

在 Django1.10 中不推荐使用模式。因此,不要导入“模式”,您的 url 模式应如下所示:

from django.conf.urls import include, url

urlpatterns=[
    url(r'^admin/', include(admin.site.urls)),
    url(........),
]

回答by Davinder

I ran into this error when trying to install Django-Guardian. Instead of downgrading Django, you can install the latest version of Django-Guardian. Try,

我在尝试安装 Django-Guardian 时遇到了这个错误。您可以安装最新版本的 Django-Guardian,而不是降级 Django。尝试,

pip install 'django-guardian>=1.4.6'

This resolved the issue for me.

这为我解决了这个问题。