user115391
user115391

Reputation: 305

Reverse for 'detail' with arguments '('',)' and keyword arguments '{}' not found. 1 pattern(s) tried:

A Django/Python newbie here. I am using python 3.4 and Django 1.7 version.

I am trying to get get my index page with hyperlinks to load and I see this issue.

My index.html (removed unwanted lines)

<form action="{% url 'testapp:search' %}" method="get">
{% csrf_token %}

        <a href="{% url 'testapp:detail' morphological %}"">Morphological</a> 

</form>

urls.py

from django.conf.urls import patterns, url

from testapp import views

urlpatterns = patterns('',
    #url(r'^$', views.IndexView.as_view(), name='index'),
    url(r'^$', 'testapp.views.index', name='index'),
    #url(r'^search-form/$', views.IndexView.as_view(), name='index'),
    url(r'^search-form/$', 'testapp.views.index', name='index'),
    #url(r'^(?P<pk>\d+)/$', views.DetailView.as_view(), name='detail'),
    #url(r'^option=(?P<option>\d+)/$', views.DetailView.as_view(), name='detail'),
    url(r'^detail/(?P<val>\w+)/?$', 'testapp.views.detail', name='detail'),
    #url(r'^search/$', views.search, name='search'),
    url(r'^search/$', views.search, name='search'),
)

views.py

from django.shortcuts import render, get_object_or_404
from django.shortcuts import render_to_response

# Create your views here.
from django.http import HttpResponse, HttpResponseRedirect

#from polls.models import Question, Choice

from testapp.models import Molecular, Morphological

#from django.template import RequestContext, loader

from django.http import Http404
from django.core.urlresolvers import reverse
from django.template import RequestContext

from django.views import generic

def index(request):
    return render_to_response('testapp/index.html', context_instance=RequestContext(request))

def search(request):
    if 'q' in request.GET:
        message = 'You searched for: %r' % request.GET['q']
    else:
        message = 'You submitted an empty form.'
    return HttpResponse(message)

def detail(request, val):
    message = 'hello form.'
    return HttpResponse(message)


#class DetailView(generic.DetailView):
#    model = Morphological
#    template_name = 'testapp/detail.html'

I am trying to pass a parameter if the link is clicked and use that parameter to query the DB. I tried various things, & at this point I am stuck. I want a string and not the primary key, which I used in the standard polls application. Is it just my regular expression wrong?

Any help in fixing this would be of great help. Thanks.

Upvotes: 1

Views: 6974

Answers (1)

Aaron Lelevier
Aaron Lelevier

Reputation: 20780

Put single-quotes around the argument in the URL:

<a href="{% url 'testapp:detail' 'morphological' %}"">Morphological</a> 

Upvotes: 5

Related Questions