首页 > 解决方案 > 指向 Django 中的 index.html

问题描述

我刚刚更新到 django 的较新版本,现在无法指向我的 index.html 文件

这是我项目的结构

gradMVPV1
--> .idea
--> catalog
    views
    models
    apps
    ....
--> gradMVPV1
    settings
    urls
    wsgi
    ....
--> templates
---->index.html
db.sqlite3
manage.py

这是我的 settings.py 文件

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_DIR = os.path.join(BASE_DIR, '/templates')

网址.py

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', views.index, "index"),
]

和意见

def index(request):
    return render(request, "index.html")

这是我的错误信息

 ValueError at /
dictionary update sequence element #0 has length 1; 2 is required
Request Method:
GET
Request URL:
http://127.0.0.1:8000/
Django Version:
2.2.7
Exception Type:
ValueError
Exception Value:
dictionary update sequence element #0 has length 1; 2 is required
Exception Location:
C:\Users\User\Anaconda3\lib\site-packages\django\urls\resolvers.py in resolve, line 348
Python Executable:
C:\Users\User\Anaconda3\python.exe
Python Version:
3.7.4

标签: pythondjango

解决方案


修复path('', views.index, "index"),]path('', views.index, name = "index"),]


推荐阅读