为什么我在django中遇到类型错误?

时间:2018-03-27 07:42:03

标签: django

所以我试图在views.py中传递一个查询,它在python shell中运行得很好。我在django项目中面临问题。

views.py:

  get 'marcels' => 'marcels#index'
  post 'import_marcels' => 'marcels#import'

我的urls.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})

我得到以下追溯:

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

任何人都可以帮我找到错误吗?

1 个答案:

答案 0 :(得分:3)

从此

更改您的网址
url(r'locate/', views.locate, name = 'locate'),

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