python - 带有参数抛出错误的 django href url
问题描述
我对一个简单的href
下载页面进行了以下设置:
网址.py
urlpatterns = [
url(r'^kpis/$', InternalKPIView.as_view(), name='internal_kpis'),
url(r'^tenants/$', TenantListView.as_view(), name='tenant-list'),
url(r'^tenants/(?P<pk>[0-9]+)/$', TenantStatsView.as_view(), name='tenant-stats'),
url(r'^fileformaterror/$', FileFormatErrorView.as_view(), name='file-format-error'),
url(r'^fileformaterror/download/(?P<s3_key>.*)$', FileFormatErrorDownloadView.as_view(), name='file-format-error-download'),
]
模板.html:
<a href="{% url 'file-format-error-download' s3_key=file.s3_key %}" target="_blank">Download</a>
视图.py:
class FileFormatErrorDownloadView(View):
def get(self, request, s3_key):
pass
但是执行时出现以下错误:
django.urls.exceptions.NoReverseMatch: Reverse for 'file-format-error-download' not found. 'file-format-error-download' is not a valid view function or pattern name.
相关文件的树输出:
$ tree -I "*.pyc|__pycache__"
.
├── apps.py
├── __init__.py
├── migrations
│ └── __init__.py
├── templates
│ └── backoffice
│ ├── file_format_error.html
│ └── internal_kpis.html
├── urls.py
└── views.py
3 directories, 7 files
解决方案
从您提供的内容来看,urls.py
您所展示的似乎属于项目中的一个应用程序。我的猜测是该应用程序的 URL 要么未正确包含,要么包含在命名空间中。
推荐阅读
- python - roc_curve() sklearn 的“ValueError:不支持多标签指示符格式”
- azure - 使用 API 与 Microsoft Teams 集成
- java - 如何从xml java中没有属性的标签中获取值
- list - SwiftUI 搜索栏被键盘推离屏幕
- scala - 一些消费者只获得一个分区和一些消费者数据的所有分区的相同消费者组ID
- python-3.x - 如何在 Matplotlib 中仅显示条形图的顶部边缘?
- kubernetes - 对 Kubernetes 服务中的端点使用 https 协议
- vhdl - 近文本“过程”;期待“如果”VHDL
- visual-studio-code - 我无法再更改 vscode 中的任何设置
- python - 无法使用videoCapture opencv打开视频