我的代码为:

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

具体的错误为:

'Specifying a namespace in include() without providing an app_name is not supported. Set the app_name attribute in the included module, or pass a 2-tuple containing the list of patterns and app_name instead.'

查找错误出处,为conf.py文件

源代码如下:

def include(arg, namespace=None):app_name = Noneif isinstance(arg, tuple):# Callable returning a namespace hint.try:urlconf_module, app_name = argexcept ValueError:if namespace:raise ImproperlyConfigured('Cannot override the namespace for a dynamic module that ''provides a namespace.')raise ImproperlyConfigured('Passing a %d-tuple to include() is not supported. Pass a ''2-tuple containing the list of patterns and app_name, and ''provide the namespace argument to include() instead.' % len(arg))else:# No namespace hint - use manually provided namespace.urlconf_module = argif isinstance(urlconf_module, str):urlconf_module = import_module(urlconf_module)patterns = getattr(urlconf_module, 'urlpatterns', urlconf_module)app_name = getattr(urlconf_module, 'app_name', app_name)if namespace and not app_name:raise ImproperlyConfigured('Specifying a namespace in include() without providing an app_name ''is not supported. Set the app_name attribute in the included ''module, or pass a 2-tuple containing the list of patterns and ''app_name instead.',)namespace = namespace or app_name# Make sure the patterns can be iterated through (without this, some# testcases will break).if isinstance(patterns, (list, tuple)):for url_pattern in patterns:pattern = getattr(url_pattern, 'pattern', None)if isinstance(pattern, LocalePrefixPattern):raise ImproperlyConfigured('Using i18n_patterns in an included URLconf is not allowed.')return (urlconf_module, app_name, namespace)

从include()函数可以看出来,这个函数有两个参数,一个arg,一个namespace,我在代码中也是两个参数,但是异常中提示了,没有提供app_name,还提示需要传入一个两元元组,从第六行代码

urlconf_module, app_name = arg

可以看出来,arg就是那个元组,且给app_name赋值了,所以我们这里修改代码为:

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

问题解决。

Django2.0异常:Specifying a namespace in include() without providing an app_name is not supported.相关推荐

  1. Specifying a namespace in include() without providing an app_name is not supported 记录

    背景 运行 Django3.0 的时候 报错, 具体表现如下: Specifying a namespace in include() without providing an app_name is ...

  2. 关于Django Specifying a namespace in include() without providing an app_name

    运行环境 PyCharm 2017.1 Django 2.0.1 python 3.6.1 在网页项目中使用include()方法 项目目录中同时存在app/urls.py和proj/urls.py ...

  3. django报错: Specifying a namespace in include() without providing an app_name

    django报错: 'Specifying a namespace in include() without providing an app_name ' django.core.exception ...

  4. django2.1学习笔记-报错:'Specifying a namespace in include() without providing an app_name '

    在根目录下的urls.py中使用了include方法,并且使用了namespace参数,如下图: 在启动项目时,会报错:'Specifying a namespace in include() wit ...

  5. Djang1.8+Python2.0迁移到Django2.0+Python3.6注意事项(转)

    Djang1.8+Python2.0迁移到Django2.0+Python3.6注意事项 参考:https://blog.csdn.net/weixin_40475396/article/detail ...

  6. django mysql5.7_GitHub - qiubiteme/DjangoBloger: 一个Django2.0+mysql57,实现的响应式博客

    项目背景介绍,这是一个简单的博客项目, 在windows10环境下开发 基于python3.6.5 Django2.0 mysql5.7开发 计划后续开发为一个前后分离,现在简单的部署使用 部署环境 ...

  7. vue+django2.0.2-rest-framework 生鲜项目(三)

    vue+django2.0.2-rest-framework 生鲜项目 一.xadmin后台管理系统配置 不使用Django自带admin后台管理,使用xadmin后台管理,类似CRM项目中的king ...

  8. django2.0 快速实现注册

    django 快速实现注册 本操作环境: 虚拟环境:django2.0 python3.5(应该python3.6都可以使用) window10 1.创建项目与应用(项目和应用都是自己制定的) 创建项 ...

  9. Django2.0+Bootstrap书籍管理系统

    项目介绍 本篇书籍管理系统的主要功能是简易图书的添加,修改及删除.可作为Django入门者的学习教程.如有错误或者建议,还望多多指教.书籍列表的页面如下: 源码链接:下载 技术工具: Python3. ...

最新文章

  1. 2022-2028年中国锅仔片行业研究及前瞻分析报告
  2. 【数据挖掘】基于密度的聚类方法 - OPTICS 方法 ( 核心距离 | 可达距离 | 族序 )
  3. Java中的同步集合与并发集合有什么区别?
  4. ORA-01180: can not create datafile 1 :解决一例
  5. 前端学习(1395):多人管理项目15建立请求
  6. Eclipse添加JDK源码
  7. Openwrt 软件安装源
  8. ctf 改变图片高度_CTF中.htaccess文件的利用
  9. CorelDRAWX4的VBA插件开发(二十六)深度转曲之包含容器内文字转曲
  10. 新浪和腾讯微博开放平台比较
  11. “头号电脑黑客” 凯文.米特尼克 与 中国台湾的”电脑鬼才“陈盈豪
  12. ebay注册流程_2018eBay注册开店流程?
  13. 哈工大计算机学院张宏莉,计算机科学与技术学科博士研究生培养方案2014-哈工大计算机学院.DOC...
  14. 遥感影像目标检测:从CNN(Faster-RCNN)到Transformer(DETR)
  15. React受控非受控组件详解,PureComponent介绍,Refs, children属性详解
  16. spoolsv.exe占cpu 99%的解决方法
  17. 会声会影2022最新版安装包下载
  18. 优地、云迹、擎朗、普渡科技的服务机器人场景战争
  19. app显示机智云服务器图片,【图片】【使用指南】机智云FAQ文档【gokit吧】_百度贴吧...
  20. 数字商业帝国-亚马逊

热门文章

  1. 准备机试时候不懂的问题
  2. 奥奇传说系统服务器繁忙,为什么所有的
  3. 工作中遇到的专业术语缩写总结
  4. JAVA ulimit,ulimit 为何不生效
  5. refs格式linux支持么,轻松开启Windows 10的ReFS文件系统
  6. 北漂程序猿约会大学班花,竟发现彼此都……
  7. splinter使用
  8. import mxnet 报错
  9. 2024内蒙古民族大学100210外科学724西医综合生理学考研强化5套卷
  10. BIEE 12C更换rpd资料库