Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python django href url带有参数抛出错误_Python_Django - Fatal编程技术网

Python django href url带有参数抛出错误

Python django href url带有参数抛出错误,python,django,Python,Django,我对一个简单的href下载页面进行了以下设置: url.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_

我对一个简单的
href
下载页面进行了以下设置:

url.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'),   
]
path('fileformaterror/download/<s3_key>/', FileFormatErrorDownloadView.as_view(), name='file-format-error-download')
但在执行时,我得到以下错误:

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

为什么不使用django2.0+?然后,代码可能如下所示:

url.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'),   
]
path('fileformaterror/download/<s3_key>/', FileFormatErrorDownloadView.as_view(), name='file-format-error-download')

从您提供的内容来看,您显示的
url.py
似乎属于项目中的一个应用程序。我猜该应用程序的URL要么没有正确包含,要么包含在名称空间中。

为什么需要。*在(?p*)中?您应该显示完整的错误消息。和完整的url.py;这是通过名称空间包含的吗?@Gnoliz它应该匹配任何内容,我想它可以省略为well@DanielRoseman我现在更新了完整的urlpatterns。请验证将
href
值替换为
{%url'文件格式错误“%}
是否可以正常工作?应用程序正在运行Django 1.11.9,我不能简单地切换到2.0I添加了树输出这是我不愿意在公共论坛上发布的大量输出tbh,你到底在找什么?我想看看
urls.py
wsgi.py
的同一个目录下的
urls.py
的内容。是的,这个特定的
urls.py
被导入到另一个
urls.py
中,它添加了一个名称空间。非常感谢你的帮助!
<a href="{% url 'file-format-error-download' file.s3_key %}" target="_blank">Download</a>
from django.shortcuts import HttpResponse
class FileFormatErrorDownloadView(View):
    def get(self, request, s3_key):
        return HttpResponse('success')