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

147
Views
obteniendo html del filtro y agregando en django

Hola, quiero saber cómo puedo obtener datos del filtro y agregarlos en mi html. Recibo este error Uncaught SyntaxError: Unexpected token '<'

HTML

 <span id='securedata'></span> <script> window.onscroll = () => { if (window.innerHeight + window.scrollY >= document.body.offsetHeight) { document.querySelector('body').style.background = 'purple'; <!--my problem is --> $('#securedata').append("{% recommend_community_first request.user.pk %}"); } else { document.querySelector('body').style.background = 'white'; } } </script>

templatetags/load_recomendación.py:

 @register.inclusion_tag('community/recommend_not_recommend.html') def recommend_community_first(user_id): user = User.objects.get(id=user_id) community = Community.objects.all().order_by('-popularity')[:6] post = Post.objects.filter(community__in=[i.pk for i in community],video__isnull=True).order_by('-created') return {'posts':post,'moi':user}

¿Cómo puedo agregar esos datos de mi filtro sin ningún error? Gracias

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Para acceder a las variables de plantilla de Django en JavaScript

Solo haz esto:

 <script> let my_url = "{% url 'recommend_community_first' request.user.pk %}"; // Or if it is {{ }} kind let my_var = '{{ context_name_variable }}'; // Here you can use these variable $('#securedata').append(my_url); </script>

El truco es usar siempre comillas ( '' o "" ) en su variable en la sección JS.

about 4 years ago · Juan Pablo Isaza 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!