• 记一次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')),
    ]
  • 相关阅读:
    [AHOI2006]文本编辑器 Splay tree区间操作
    HDU-3487 Play with Chain Splay tee区间反转,移动
    HDU-4619 Warm up 2 二分匹配
    HDU-4618 Palindrome Sub-Array 暴力枚举
    HDU-4616 Game 树形DP
    HDU-4614 Vases and Flowers 线段树区间更新
    HDU-4612 Warm up 边双连通分量+缩点+最长链
    HDU-4611 Balls Rearrangement 循环节,模拟
    HDU-4605 Magic Ball Game 树状数组+离散+dfs
    HDU-3436 Queue-jumpers 树状数组 | Splay tree删除,移动
  • 原文地址:https://www.cnblogs.com/mswei/p/9988197.html
Copyright © 2020-2023  润新知