如何解决:typeerror:“ Catg_id”是无效的关键字参数

时间:2019-06-12 00:21:45

标签: python django python-3.x

运行上面的代码时,出现错误:

TypeError: 'Catg_id' is an invalid keyword argument for this function" for the function named as 'ch' above. 

如何解决此错误?

from categories.models import Catg, Type, Product, Choice
from django.shortcuts import render

def ch(request, Type_id, Product_id, Catg_id):
    ca = Catg.objects.get(pk=Catg_id)
    p = Type.objects.get(pk=Type_id)
    cho = Product.objects.get(pk=Product_id)
    alls = Choice.objects.all()
    context3 = {
        'p': p,
        'alls': alls,
        'cho': cho,
        'ca': ca,
    }
    return render(request, "service providers.html", context3)

还在URL.PY中输入

url(r'^categories/(?P<Catg_id>[0-9])/(?P<Type_id>[0-9]+)/(?P<Product_id>[0-9]+)/$', views.Choice, name='choice'),

AND IN MODELS.PY

class Choice(models.Model):
    chname = models.ForeignKey(Product, on_delete=models.CASCADE)
    chn = models.CharField(max_length=1000, default=" ")


    def __str__(self):
        return self.chn

1 个答案:

答案 0 :(得分:0)

关于我的评论,您需要类似

import views

url(r'^categories/(?P<Catg_id>[0-9])/(?P<Type_id>[0-9]+)/(?P<Product_id>[0-9]+)/$', views.ch, name='ch'),