Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

324
Views
Django Rest Framework Copeapi LinkLookupError

Obtengo un LinkLookupError cuando intento obtener un punto final servido por Django Rest Framework. Este error solo ocurre después de una sola solicitud exitosa. Mi DRF view.py se parece a:

 class RecordViewSet(viewsets.ReadOnlyModelViewSet): """ API endpoint that allows Records to be viewed or edited. """ filter_backends = (SimpleRecordFilterBackend,) serializer_class = RecordSerializer permission_classes = (IsAuthenticated,) @action(detail=False, url_path='tagsum/(?P<account>[^/.]+)/(?P<tag>[^/.]+)') def tagsum(self, request, account, tag): if not account or not tag: return Response({'status': "need accoutn and tag"}) sum = Records.objects.filter(linkedaccount_id=account).filter(user_project=tag).aggregate(total=Sum('unblendedcost')) return Response({'sum': sum['total']}) def get_queryset(self): q = Q() linkedaccount_id = self.request.query_params.get("linkedaccount_id") or '' user_project = self.request.query_params.get("user_project") or '' if linkedaccount_id: q &= Q(linkedaccount_id=linkedaccount_id) if user_project: q &= Q(user_project=user_project) return Records.objects.filter(q).annotate(Sum('unblendedcost'))

Después de modificar el archivo de vista, llamo a $ coreapi get http://localhost:8000/api/docs/ y veo:

 ... records: { list([page], [linkedaccount_id], [productname], [user_project]) tagsum(account, tag) read(id, [linkedaccount_id], [productname], [user_project]) } ...

y después de cargar una página que llama a ese punto final, cuando ejecuto el mismo comando, veo este resultado:

 ... records: { tagsum: { read(account, tag) } list([page], [linkedaccount_id], [productname], [user_project]) read(id, [linkedaccount_id], [productname], [user_project]) } ...

Tenga en cuenta que el método tagsum ahora tiene el método de lectura anidado. Las llamadas al extremo ahora devuelven el siguiente error.

 errors.js:10 Uncaught LinkLookupError: Invalid link lookup: ["records","tagsum"] at new LinkLookupError (errors.js:10) at lookupLink (client.js:19) at Client.action (client.js:38) at eval (ProjectTagBilling.js:40) at invokePassiveEffectCreate (react-dom.development.js:23482) at HTMLUnknownElement.callCallback (react-dom.development.js:3945) at Object.invokeGuardedCallbackDev (react-dom.development.js:3994) at invokeGuardedCallback (react-dom.development.js:4056) at flushPassiveEffectsImpl (react-dom.development.js:23569) at unstable_runWithPriority (scheduler.development.js:468)

Cualquier consejo sería apreciado.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Solución alternativa, use fetch. 😞

HTML

 <script> const csrftoken = document.querySelector('[name=csrfmiddlewaretoken]').value; </script>

JS

 useEffect(() => { setIsLoading(true) fetch(`/api/records/tagsum/${'432399220289'}/${props.tag}/`, { headers: {'X-CSRFToken': csrftoken}, mehtod: 'GET' }).then(response => response.json()).then(result => { setIsLoading(false) setSum(result.sum) }) },[])
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!