我正在使用django 2.1.4和python 3.6.7。当我尝试运行我的应用程序时,我出现了一个错误 NoReverseMatch at/depotanone/ 找不到具有关键字参数“{args':[26,3]}”的“meschambre”的反转。尝试了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)
URL.py:
path('depotAnnonce/mesChambres/<idAnn>/<nbCh>', views.MesChambreView.as_view(), name ='mesChambres'),
redirect
的语法要求*args
和**kwargs
。所以你会写:相关问题 更多 >
编程相关推荐