找不到带有关键字参数“”的“”的NoReverseMatch

时间:2019-02-27 15:48:19

标签: python django

我正在使用Django 2.1.4和python 3.6.7。当我尝试运行我的应用程序时出现错误 / depotAnnonce /中的NoReverseMatch 找不到带有关键字参数'{'args':[26,3]}'的'mesChambres'。尝试了1个模式:['depotAnnonce \ / mesChambres \ /(?P [^ /] +)\ /(?P [^ /] +)$']

views.py:

class DepotAnnView(TemplateView):
        template_name = "base/depotann.html"

    def get(self, request):
        form = Annonceform()
        return render(request, self.template_name, {'form': form})

    def post(self, request):
        util = Annonceur.objects.filter(user_id=request.user.id)[0]
        form = Annonceform(request.POST)
        if form.is_valid():
            titre = form.cleaned_data['titre']
            nbChambre = form.cleaned_data['nbChambre']
            superficie = form.cleaned_data['superficie']
            loyer = form.cleaned_data['loyer']
            bail = form.cleaned_data['bail']
            animaux = form.cleaned_data['animaux']
            fumeur = form.cleaned_data['fumeur']
            description = form.cleaned_data['description']
            id = Annonce.objects.count()+1
            ann = Annonce(id, titre, nbChambre, superficie, loyer, bail, nbChambre, animaux, fumeur, description, request.user.id)
            ann.save()
            return redirect('mesChambres', args=[id,nbChambre])
        return render(request, self.template_name, {'form' : form})

class MesChambreView(TemplateView):
    template_name = "base/mesChambres.html"

    def get(self, request, idAnn, nbCh):
        reponse = request.args
        form = Chambreform()
        return render(request, self.template_name, {'form': form}, reponse)


    def post(self, request):
        reponse = request.args
        form = Chambreform(request.POST)
        if form.is_valid():
            loyerCh = form.cleaned_data['loyerCh']
            superficieCh = form.cleaned_data['superficieCh']
            ch = Chambre(Chambre.objects.count()+1, reponse[0], loyerCh, superficieCh)
            ch.save()
            return redirect('index')
        return render(request, self.template_name, {'form': form}, reponse)

urls.py:

 path('depotAnnonce/mesChambres/<idAnn>/<nbCh>', views.MesChambreView.as_view(), name ='mesChambres'),

1 个答案:

答案 0 :(得分:0)

redirect的语法应为*args**kwargs。所以你会写:

return redirect('mesChambres', id, nbChambre)