新手Django问题

时间:2017-03-08 18:19:50

标签: python django

我收到了这个错误:

  

NoReverseMatch at / genomics / Reverse for“pipelinedetail”with   arguments'('02152ad7-8399-441c-ba8f-f8871460cd5f',)'和关键字   没有找到参数“{}”。尝试了0种模式:[]

当我导航到此网址时:

  

http://127.0.0.1:8000/genoa/

我的genoa_urls.py有:

urlpatterns = [
    # ex: /polls/samples
    url(r'^$', views.samples, name='samples'),
    url(r'^(?P<sequence_id>[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})/pipelinedetail/$', views.pipelinedetail,  name='pipelinedetail'),
]

我模板中的违规行是:

<td><a href="{% url 'polls:pipelinedetail' me.sequence_id %}">JSON</a></td>

我的观点包含:

def pipelinedetail(request, sequence_id):
    # sequence_id = '7e6bd861-934f-44be-872a-b59826107bda'
    sample = get_object_or_404(Sample, pk=sequence_id)
    sample_details = sample.values('pipeline_detail')
    context = {'sample_details': sample_details}
    return render(request, 'polls/pipelinedetail.html', context)

这是顶级urls.py:

urlpatterns = [
    # polls in the url maps to polls.urls.py
    url(r'^polls/', include('polls.urls')),
    url(r'^genoa/', include('polls.genoa_urls')),
    url(r'^admin/', admin.site.urls),
]

我做错了什么?

2 个答案:

答案 0 :(得分:1)

您的民意调查网址不在命名空间中,因此您不需要前缀。

{% url 'pipelinedetail' me.sequence_id %}

答案 1 :(得分:0)

在我创建新应用并将新代码放在那里之后,您的两条建议最终都与原始代码一样有效。谢谢。