python - 指向 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
解决方案
修复path('', views.index, "index"),]
成
path('', views.index, name = "index"),]
推荐阅读
- unit-testing - 带有 Spock 框架模拟“_”选项的 Groovy 扩展运算符
- android - Mono Android 和 Xamarin.android 之间的区别
- rest - 是否建议将所有场景响应数据保存到外部文件中并在代码内部而不是功能文件中读取?
- angular - 同时添加/删除元素时列表项动画不起作用
- python - 如何通过 python 请求登录到 Iptorrents.com
- python - 在 Google Colab 中使用自定义库而不安装驱动器
- alexa - 如何让用户说出失败的话语?
- javascript - 将 React 路由组件传递给父组件 props 函数
- python - 运行 json.loads 后出现 KeyError
- python-3.x - “如何修复”AttributeError:“list”对象没有“translate”属性