記一次Django報錯Reverse for 'indextwo' with no arguments not found. 1 pattern(s) tried: ['$index/$']
阿新 • • 發佈:2018-11-20
啟動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')), ]