
这是我在浏览器中出现的错误:
TypeError at /batches/index() missing 1 required positional argument: 'pk'Request Method: GETRequest URL: http://127.0.0.1:8000/batches/Django Version: 1.11.1Exception Type: TypeErrorException Value: index() missing 1 required positional argument: 'pk'Exception Location: /library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/handlers/base.py in _get_response,line 185Python Executable: /library/Frameworks/Python.framework/Versions/3.6/bin/python3.6Python Version: 3.6.1Python Path: ['/Users/cohen/documents/project/sanctions','/Users/cohen/documents/project/sanctions','/library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip','/library/Frameworks/Python.framework/Versions/3.6/lib/python3.6','/library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload','/library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages','/library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyObjC']Server time: Mon,24 Jul 2017 10:47:02 +0000
我的网址分批
from django.conf.urls import urlfrom . import vIEwsurlpatterns = [ # /batches/ url(r'^$',vIEws.index,name='index'),# /batches/2 url(r'^(?P<batches_ID>[0-9]+)/$',vIEws.detail,name="detail"),# businessname/1 url(r'^(?P<businessname_ID>[0-9]+)/$',vIEws.index_businessname,name="detail_businessname"),# indivIDuals/1 url(r'^(?P<indivIDuals_ID>[0-9]+)/$',vIEws.index_indivIDuals,name="detail_indivIDuals"),]
意见:
# -*- Coding: utf-8 -*-from __future__ import unicode_literalsfrom .models import Businessnamefrom .models import IndivIDualsfrom .models import Batchesfrom django.shortcuts import renderfrom django.http import httpResponse# Create your vIEws here.def index(request,pk): all_Batches = Batches.objects.all() HTML = '' for batch in all_Batches: url = '/batches/' + str(batch.ID) + '/' HTML += '<a href="#"' + url + '">' + str(batch.BatchNumber)+ '</a><br>' return httpResponse(HTML)def detail(request,batch_ID): return httpResponse("<h2>Details for Batches ID:" + str(batch_ID) + "</h2")def index_businessname(request): all_Businessnames = Businessname.objects.all() HTML = '' for bn in all_Businessnames: url = '/businessname/' + str(bn.ID) + '/' HTML += '<a href="#"' + url + '">' + bn.Fullname + '</a><br>' return httpResponse(HTML)def detail_businessnames(request,bn_ID): return httpResponse("<h2>Details for Business names ID:" + str(bn_ID) + "</h2")def index_indivIDuals(request): all_indivIDuals = IndivIDuals.objects.all() HTML = '' for i in all_indivIDuals: url = '/indivIDuals/' + str(i.ID) + '/' HTML += '<a href="#"' + url + '">' + i.Fullname + '</a><br>' return httpResponse(HTML)def detail_indivIDuals(request,i_ID): return httpResponse("<h2>Details for IndivIDual names ID:" + str(i_ID)+ "</h2") 先感谢您,
科恩
以上是内存溢出为你收集整理的python – Django错误— index()缺少1个必需的位置参数:’pk’全部内容,希望文章能够帮你解决python – Django错误— index()缺少1个必需的位置参数:’pk’所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)