环境:win10(64)+pycharm2018.3+python3.7

在网页项目中使用include()方法

  • 项目目录中同时存在app/urls.py和proj/urls.py
  • 在proj/urls.py使用include方法

代码:

urlpatterns = [
path('admin/', admin.site.urls),
re_path(r'^booktest/',include('booktest.urls',namespace='booktest')),
]
booktest/urls.py
urlpatterns = [
re_path(r'^$',views.index,name='index'),
re_path(r'^(\d+)/$',views.show,name = 'show'),
]

报错截图如下:

意思为: 

在include方法里面指定namespace却不提供app_name是不允许的。 

在包含的模块里设置app_name变量,或者在include方法里面提供app_name参数。

解决方法

方法1:在proj/urls.py中修改

urlpatterns = [
path('admin/', admin.site.urls),
re_path(r'^booktest/',include(('booktest.urls','booktest'),namespace='booktest')),
]

方法2:在app/urls.py中修改

app_name = 'booktest'
urlpatterns = [
re_path(r'^$',views.index,name='index'),
re_path(r'^(\d+)/$',views.show,name = 'show'),
]

Django报错:'Specifying a namespace in include() without providing an app_name '的更多相关文章

  1. 解决:Specifying a namespace in include() without providing an app_name和XXX is not a registered namespace问题

    python3 Django 环境下,如果你遇到namespace没有注册以及在根目录下urls.py中的include方法的第二个参数namespace添加之后就出错的问题. 出错问题: 'Spec ...

  2. 'Specifying a namespace in include() without providing an app_name '

    'Specifying a namespace in include() without providing an app_name ’ 从include()函数可以看出来,这个函数有两个参数,一个a ...

  3. 'Specifying a namespace in include() without providing an app_name '报错解决

    需要在每个ap下面的url.py 加入一个指定app的名字 比如  user  app  下的 url.py  文件加入: urlpatterns = []app_name = "user& ...

  4. django报错外理收集

    网址指向同一地址后: Forbidden (403) CSRF verification failed. Request aborted. You are seeing this message be ...

  5. django 报错Reverse for 'detail' with keyword arguments '{'pk': '2'}' not found. 1 pattern(s) tried: ['$post/(?P<pk>[0-9]+)/$']

    Django报错:Reverse for 'detail' with keyword arguments '{'pk': '2'}' not found. 1 pattern(s) tried: [' ...

  6. Django报错:OSError: raw write() returned invalid length 4 (should have been between 0 and 2)

    在使用Django时Django报错:Django报错:OSError: raw write() returned invalid length 4 (should have been between ...

  7. Django报错:提交表单报错---RuntimeError: You called this URL via POST, but the URL doesn’t end in a slash and you have APPEND_SLASH set.

    Django报错:提交表单报错---RuntimeError: You called this URL via POST, but the URL doesn’t end in a slash and ...

  8. Django 报错 Reverse for 'content' not found. 'content' is not a valid view function or pattern name.

    Django 报错 Reverse for 'content' not found. 'content' is not a valid view function or pattern name. 我 ...

  9. django报错解决:view must be a callable or a list/tuple in the case of include().

    django版本:1.11.15 django应用,修改urls.py后,访问报错:TypeError at /view must be a callable or a list/tuple in t ...

随机推荐

  1. 【NX二次开发】Block UI 超级截面

    属性说明 属性   类型   描述   常规           BlockID    String    控件ID    Enable    Logical    是否可操作    Group    ...

  2. NX二次开发-获取WCS标识

    函数:UF_CSYS_ask_wcs() 函数说明:获取工作坐标系对象的标识. 用法: 1 #include <uf.h> 2 #include <uf_csys.h> 3 e ...

  3. python学习笔记02-简单游戏

    一拖又过去快一个月了,哭聊.. 惰性千万不要有.. 今天简单接触一下条件语句 一个简单的文字游戏 1 print('----第一个文字游戏----') 2 temp = input('猜一下现在心里想 ...

  4. Vue项目的开发流程

    我先安装的node.js 1.确认已安装了node.js,可在cmd中输入( node -v和npm -v),如显示出版号,说明安装成功 2.安装webpack 和webpack-cli 在全局下安装 ...

  5. Java 提效神器 Stream 的冷门技巧

    Stream 使用这个方法创建一个 Stream 对象. new ArrayList<>().stream() Filter 过滤器,里面传递一个函数,这个函数的返回结果如果为 true ...

  6. oscp-缓冲区溢出(持续更新)

    环境准备 Windows7虚拟机(我选了IE8,其实也没什么关系) 微软官方下载地址 These virtual machines expire after 90 days. We recommend ...

  7. 6.11、制作windos虚拟机

    1.下载kvm支持windows系统的驱动程序: cd /tmp/ wget https://fedorapeople.org/groups/virt/virtio-win/direct-downlo ...

  8. 3、mysql的多实例配置(2)

    4.设置mysql多实例启动脚本: (1)3306: [root@backup application]# cat /data/3306/mysql #!/bin/sh . /etc/init.d/f ...

  9. k8s结合jumpserver做kubectl权限控制 用户在多个namespaces的访问权限 rbac权限控制

    圈子太小,做人留一面,日后好相见. 其实这个文章就是用户用jumpserver登录到k8s master节点 然后执行kubectl的时候只有自己namespaces的所有权限. 背景 1,k8s 有 ...

  10. fastjson: json对象,json对象数组,javabean对象,json字符串之间的相互转化

    fastjson: json对象,json对象数组,javabean对象,json字符串之间的相互转化 在开发过程中,经常需要和前端交互数据,数据交互的格式都是JSON,在此过程中免不了json字符串 ...