记一次Django报错Reverse for 'indextwo' with no arguments not found. 1 pattern(s) tried: ['$index/$']...

启动python manage.py runserver

打开127.0.0.1:8000,报错信息如下:

Reverse for 'indextwo' with no arguments not found. 1 pattern(s) tried: ['$index/$']

现象:

无论怎么修改views.py 还是urls.py,报错信息始终存在

 

问题发现:

项目目录结构如下

myweb
├── db.sqlite3
├── home
│   ├── __init__.py
│   ├── admin.py
│   ├── apps.py
│   ├── migrations
│   │   └── __init__.py
│   ├── models.py
│   ├── tests.py
│   ├── urls.py
│   └── views.py
├── manage.py
├── myweb
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   ├── wsgi.py
├── static
│   ├── images
│   │   ├── 55adde120001d34e00410041.png
│   │   ├── 55addf800001ff2e14410118.png
│   │   ├── 55addfcb000189b314410138.png
│   │   ├── background.jpg
│   │   ├── body_back.jpg
│   │   └── title.ico
│   └── jc
│       ├── 55ac9a860001a6c500000000.js
│       ├── 55ac9ea30001ace700000000.js
│       ├── jquery.easing.min.js
│       ├── jquery.fancybox.css
│       ├── sample-style.css
│       ├── scripts.js
│       ├── skin.css
└── templates
    ├── index.html
    ├── index_three.html
    └── index_two.html

问题就出现在上面的两个urls.py中

在myweb的文件夹下的urls.py中,代码如下:

from django.conf.urls import url, include

urlpatterns = [
    url(r'^$', include('home.urls')),
]

在home的文件下的urls.py中,代码如下:

from django.conf.urls import url
from .views import HomeHtml

urlpatterns = [
    url(r'^$', HomeHtml().index, name='index'),
    url(r'^index/$', HomeHtml().index_two, name='indextwo'),
    url(r'^content/', HomeHtml().content, name='content'),
    url(r'^showlist/', HomeHtml().showlist, name='showlist')
]

 

解决:

将规则改为如下,项目正常启动,无报错信息

from django.conf.urls import url, include

urlpatterns = [
    url(r'^', include('home.urls')),
]

 

转载于:https://www.cnblogs.com/mswei/p/9988197.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值