Arjun Kashyap
Arjun Kashyap

Reputation: 663

Why am I getting a type error in django?

So I am trying to pass a query in views.py which is working just fine in python shell. I am facing problem in my django project.

views.py:

def result(request):            # Shows the matched result
    query = request.GET.get('inc_search')
    check = Incubators.objects.filter(incubator_name__icontains= query).exclude(verify = False)
    return render(request, 'main/results.html', {'incubators': incubators,'check': check})

def details(request, incubator_id):
    inc = get_object_or_404(Incubators, pk = incubator_id)
    details = Details.objects.get(pk = incubator_id)
    return render(request, 'main/details.html', {'inc': inc, 'details': details})


def locate(request, incubator_id):
    pos = Incubators.objects.values_list('latt', 'lonn').filter(pk = incubator_id)
    return render(request, 'main/locate.html', {'pos': pos})

My urls.py is below:

url(r'location/', views.location, name = 'location'),
url(r'prediction/', views.prediction, name = 'prediction'),
url(r'locate/', views.locate, name = 'locate'),

I am getting the following traceback:

TypeError at /locate/

locate() missing 1 required positional argument: 'incubator_id'

Request Method:     GET
Request URL:    http://127.0.0.1:8000/locate/
Django Version:     1.11.3
Exception Type:     TypeError
Exception Value:    

locate() missing 1 required positional argument: 'incubator_id'

Can anyone help me find the error?

Upvotes: 0

Views: 567

Answers (1)

Exprator
Exprator

Reputation: 27503

change your url from this

url(r'locate/', views.locate, name = 'locate'),

to

url(r'locate/(?P<incubator_id>\d+)/$', views.locate, name = 'locate'),

Upvotes: 3

Related Questions