我試圖根據每個客戶限制對記錄的訪問,以便用戶無法通過 URL 訪問彼此的資料。我已經添加了這個但是它限制了一切。請幫忙。
if request.user.customer != Infringement.customer: return HttpResponse('你不能在這里!!')"
視圖.py
@login_required(login_url='login') def infringement(request, pk): if request.user.customer != Infringement.customer: return HttpResponse('Your are not allowed here!!') infringement = Infringement.objects.get(id=pk) notes = infringement.note_set.all().order_by('-created') if request.method == "POST": note = Note.objects.create( customer=request.user.customer, user = request.user, infringement = infringement, body=request.POST.get('body') ) return redirect('infringement', pk=infringement.id) context= {'infringement': infringement, 'notes': notes} return render(request, 'base/infringements.html', context)
uj5u.com熱心網友回復:
嘗試:
@login_required(login_url='login')
def infringement(request, pk):
infringement = Infringement.objects.get(id=pk)
if request.user.customer.id != infringement.customer.id:
return HttpResponse('Your are not allowed here!!')
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/533579.html
