Tuesday, February 25, 2020

Re: django context data into javascript

Hi!

The context is a dictionary mapping template variable names to Python objects.

May be you need to test with a dict nor string directly.
I haven't test a direct variable.

Try not using JS, first resolve dict context in html , then JS.

Luck!

Missatge de Soumen Khatua <soumenkhatua258@gmail.com> del dia dt., 25 de febr. 2020 a les 11:25:
Hi Folks,

I'm sending some context data into html like 
name = 'soumen'
return render(request,'xyz.html', context = {'name':name})

inside myjs.js(js script has been integrated to html):
-------------------------------------------------------------------
var my_name = {{name}};

I'm getting an error::: Uncaught SyntaxError: Unexpected token '{'

So,How I can render data into frontend??

Thank You in advance

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPUw6WYM%2BvkoRqOaUn0%2Bt0j9fBf%2BhUZ2myvfsfY4qoBmLAgTfw%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK-JoTRqi_2rRoshwmr7G74%3DH6STp0LSL_4nKBsODpi4%2BwrrCw%40mail.gmail.com.

No comments:

Post a Comment