Re: How to use django template tags in .js file ??

2021-06-17 Thread Ayush Bisht
thanks, It works for me  

On Wednesday, June 16, 2021 at 12:08:20 PM UTC-7 Nikeet NA wrote:

> Or you can store the url in the variable then use it.
>
> On Thursday, 17 June 2021 at 00:29:00 UTC+5:30 Nikeet NA wrote:
>
>> Do like this use 
>> var obj_slug = object.slug inside script tag below it include your js 
>> file with the above js script. in js file you can acces it with obj_slug 
>> variable.
>>
>> On Wednesday, 16 June 2021 at 22:31:39 UTC+5:30 kuassi...@paydunya.com 
>> wrote:
>>
>>> I also had the problem once. But what I understood is that the 
>>> interpretation of the DJANGO syntax in statics files only works when the 
>>> file has an HTML extension. So if you really want to do something separate 
>>> with the script you can just create another HTML file but in another folder 
>>> where you will put the script content surrounded by the SCRIPT tags and 
>>> then you will just include with the directive {% INCLUDE %} in 
>>> your main HTML file.
>>>
>>> On Wednesday, June 16, 2021 at 3:59:16 PM UTC bisht.a...@gmail.com 
>>> wrote:
>>>
 while doing great stuff with django I have found some clumsy behaviour 
 of django in handling .js file. Is there a way to effectively integrate 
 all 
 the stuff of   in a separate file and effectively used it 
 with rest of the html code. 

 for example : 

 // *file.html 
 ..*

 
   

 >>> method="POST" id="likes-form">
 {% csrf_token %}

 >>> id="like-{{
 object.pk}}">
 
   
   
 {{ object.total_likes }}
   
 




 //  *file.js file*  
 ..

 $("#likes-form").submit(function (e)
 {  e.preventDefault();
   var serializedData = $(this).serializeArray();
   $.ajax({
   type: 'POST',
   url: '{% url 'blog_likes' object.slug  %}',
   data: serializedData,
   success: function (response) {
 var like_count = JSON.parse(response["like"]);
 like_flag = JSON.parse(response["flag"]);
 
 console.log(like_flag);
   
 if(like_flag == 0){  
 $(".like-inner-flex-1").toggleClass('like-animate');   
   }else
   $(".like-inner-flex-1").toggleClass('like-animate'); 
   
   if(like_flag){

   $('.like-btn').css({"background-color": "#d629801a" , "outline": 
 "none"});

 $('.like-inner-flex-1').css({"background-position": "right",  
 "filter": "grayscale(0%)"});

 } else {

 $('.like-btn').css({"background-color": "transparent", "outline": 
 "none"});

 $('.like-inner-flex-1').css({"background-position": "right",  
 "filter": "grayscale(100%)"});

 }

 $("#likes").text(`${like_count}`);
 }})
 })

 ..

 if I use above script inside the same html file then it works, but in 
 above case its not working ?? If there is any work around to do this thing 
 , then please suggest me .

 Thank you...

  




-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0e2ac9d2-60ef-4acf-b69f-8f0ba70eeffbn%40googlegroups.com.


Re: How to use django template tags in .js file ??

2021-06-16 Thread Nikeet NA
Or you can store the url in the variable then use it.

On Thursday, 17 June 2021 at 00:29:00 UTC+5:30 Nikeet NA wrote:

> Do like this use 
> var obj_slug = object.slug inside script tag below it include your js file 
> with the above js script. in js file you can acces it with obj_slug 
> variable.
>
> On Wednesday, 16 June 2021 at 22:31:39 UTC+5:30 kuassi...@paydunya.com 
> wrote:
>
>> I also had the problem once. But what I understood is that the 
>> interpretation of the DJANGO syntax in statics files only works when the 
>> file has an HTML extension. So if you really want to do something separate 
>> with the script you can just create another HTML file but in another folder 
>> where you will put the script content surrounded by the SCRIPT tags and 
>> then you will just include with the directive {% INCLUDE %} in 
>> your main HTML file.
>>
>> On Wednesday, June 16, 2021 at 3:59:16 PM UTC bisht.a...@gmail.com wrote:
>>
>>> while doing great stuff with django I have found some clumsy behaviour 
>>> of django in handling .js file. Is there a way to effectively integrate all 
>>> the stuff of   in a separate file and effectively used it 
>>> with rest of the html code. 
>>>
>>> for example : 
>>>
>>> // *file.html 
>>> ..*
>>>
>>> 
>>>   
>>>
>>> >> method="POST" id="likes-form">
>>> {% csrf_token %}
>>>
>>> >> id="like-{{
>>> object.pk}}">
>>> 
>>>   
>>>   
>>> {{ object.total_likes }}
>>>   
>>> 
>>>
>>>
>>>
>>>
>>> //  *file.js file*  
>>> ..
>>>
>>> $("#likes-form").submit(function (e)
>>> {  e.preventDefault();
>>>   var serializedData = $(this).serializeArray();
>>>   $.ajax({
>>>   type: 'POST',
>>>   url: '{% url 'blog_likes' object.slug  %}',
>>>   data: serializedData,
>>>   success: function (response) {
>>> var like_count = JSON.parse(response["like"]);
>>> like_flag = JSON.parse(response["flag"]);
>>> 
>>> console.log(like_flag);
>>>   
>>> if(like_flag == 0){  
>>> $(".like-inner-flex-1").toggleClass('like-animate');   
>>>   }else
>>>   $(".like-inner-flex-1").toggleClass('like-animate'); 
>>>   
>>>   if(like_flag){
>>>
>>>   $('.like-btn').css({"background-color": "#d629801a" , "outline": 
>>> "none"});
>>>
>>> $('.like-inner-flex-1').css({"background-position": "right",  
>>> "filter": "grayscale(0%)"});
>>>
>>> } else {
>>>
>>> $('.like-btn').css({"background-color": "transparent", "outline": 
>>> "none"});
>>>
>>> $('.like-inner-flex-1').css({"background-position": "right",  
>>> "filter": "grayscale(100%)"});
>>>
>>> }
>>>
>>> $("#likes").text(`${like_count}`);
>>> }})
>>> })
>>>
>>> ..
>>>
>>> if I use above script inside the same html file then it works, but in 
>>> above case its not working ?? If there is any work around to do this thing 
>>> , then please suggest me .
>>>
>>> Thank you...
>>>
>>>  
>>>
>>>
>>>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3e005ecb-77c9-4fac-aa10-ba0d7059c758n%40googlegroups.com.


Re: How to use django template tags in .js file ??

2021-06-16 Thread Nikeet NA
Do like this use 
var obj_slug = object.slug inside script tag below it include your js file 
with the above js script. in js file you can acces it with obj_slug 
variable.

On Wednesday, 16 June 2021 at 22:31:39 UTC+5:30 kuassi...@paydunya.com 
wrote:

> I also had the problem once. But what I understood is that the 
> interpretation of the DJANGO syntax in statics files only works when the 
> file has an HTML extension. So if you really want to do something separate 
> with the script you can just create another HTML file but in another folder 
> where you will put the script content surrounded by the SCRIPT tags and 
> then you will just include with the directive {% INCLUDE %} in 
> your main HTML file.
>
> On Wednesday, June 16, 2021 at 3:59:16 PM UTC bisht.a...@gmail.com wrote:
>
>> while doing great stuff with django I have found some clumsy behaviour of 
>> django in handling .js file. Is there a way to effectively integrate all 
>> the stuff of   in a separate file and effectively used it 
>> with rest of the html code. 
>>
>> for example : 
>>
>> // *file.html 
>> ..*
>>
>> 
>>   
>>
>> > method="POST" id="likes-form">
>> {% csrf_token %}
>>
>> > id="like-{{
>> object.pk}}">
>> 
>>   
>>   
>> {{ object.total_likes }}
>>   
>> 
>>
>>
>>
>>
>> //  *file.js file*  
>> ..
>>
>> $("#likes-form").submit(function (e)
>> {  e.preventDefault();
>>   var serializedData = $(this).serializeArray();
>>   $.ajax({
>>   type: 'POST',
>>   url: '{% url 'blog_likes' object.slug  %}',
>>   data: serializedData,
>>   success: function (response) {
>> var like_count = JSON.parse(response["like"]);
>> like_flag = JSON.parse(response["flag"]);
>> 
>> console.log(like_flag);
>>   
>> if(like_flag == 0){  
>> $(".like-inner-flex-1").toggleClass('like-animate');   
>>   }else
>>   $(".like-inner-flex-1").toggleClass('like-animate'); 
>>   
>>   if(like_flag){
>>
>>   $('.like-btn').css({"background-color": "#d629801a" , "outline": 
>> "none"});
>>
>> $('.like-inner-flex-1').css({"background-position": "right",  
>> "filter": "grayscale(0%)"});
>>
>> } else {
>>
>> $('.like-btn').css({"background-color": "transparent", "outline": 
>> "none"});
>>
>> $('.like-inner-flex-1').css({"background-position": "right",  
>> "filter": "grayscale(100%)"});
>>
>> }
>>
>> $("#likes").text(`${like_count}`);
>> }})
>> })
>>
>> ..
>>
>> if I use above script inside the same html file then it works, but in 
>> above case its not working ?? If there is any work around to do this thing 
>> , then please suggest me .
>>
>> Thank you...
>>
>>  
>>
>>
>>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5646832c-ab1a-4e58-8e10-0b178ddab1c0n%40googlegroups.com.


Re: How to use django template tags in .js file ??

2021-06-16 Thread Kuassi Israel
I also had the problem once. But what I understood is that the 
interpretation of the DJANGO syntax in statics files only works when the 
file has an HTML extension. So if you really want to do something separate 
with the script you can just create another HTML file but in another folder 
where you will put the script content surrounded by the SCRIPT tags and 
then you will just include with the directive {% INCLUDE %} in 
your main HTML file.

On Wednesday, June 16, 2021 at 3:59:16 PM UTC bisht.a...@gmail.com wrote:

> while doing great stuff with django I have found some clumsy behaviour of 
> django in handling .js file. Is there a way to effectively integrate all 
> the stuff of   in a separate file and effectively used it 
> with rest of the html code. 
>
> for example : 
>
> // *file.html 
> ..*
>
> 
>   
>
>  method="POST" id="likes-form">
> {% csrf_token %}
>
>  id="like-{{
> object.pk}}">
> 
>   
>   
> {{ object.total_likes }}
>   
> 
>
>
>
>
> //  *file.js file*  
> ..
>
> $("#likes-form").submit(function (e)
> {  e.preventDefault();
>   var serializedData = $(this).serializeArray();
>   $.ajax({
>   type: 'POST',
>   url: '{% url 'blog_likes' object.slug  %}',
>   data: serializedData,
>   success: function (response) {
> var like_count = JSON.parse(response["like"]);
> like_flag = JSON.parse(response["flag"]);
> 
> console.log(like_flag);
>   
> if(like_flag == 0){  
> $(".like-inner-flex-1").toggleClass('like-animate');   
>   }else
>   $(".like-inner-flex-1").toggleClass('like-animate'); 
>   
>   if(like_flag){
>
>   $('.like-btn').css({"background-color": "#d629801a" , "outline": 
> "none"});
>
> $('.like-inner-flex-1').css({"background-position": "right",  
> "filter": "grayscale(0%)"});
>
> } else {
>
> $('.like-btn').css({"background-color": "transparent", "outline": 
> "none"});
>
> $('.like-inner-flex-1').css({"background-position": "right",  
> "filter": "grayscale(100%)"});
>
> }
>
> $("#likes").text(`${like_count}`);
> }})
> })
>
> ..
>
> if I use above script inside the same html file then it works, but in 
> above case its not working ?? If there is any work around to do this thing 
> , then please suggest me .
>
> Thank you...
>
>  
>
>
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c39ae23c-28f6-4e38-9dec-87e6d4809759n%40googlegroups.com.


How to use django template tags in .js file ??

2021-06-16 Thread Ayush Bisht
while doing great stuff with django I have found some clumsy behaviour of 
django in handling .js file. Is there a way to effectively integrate all 
the stuff of   in a separate file and effectively used it 
with rest of the html code. 

for example : 

// *file.html 
..*


  

{% csrf_token %}


  
  
{{ object.total_likes }}
  





//  *file.js file*  
..

$("#likes-form").submit(function (e)
{  e.preventDefault();
  var serializedData = $(this).serializeArray();
  $.ajax({
  type: 'POST',
  url: '{% url 'blog_likes' object.slug  %}',
  data: serializedData,
  success: function (response) {
var like_count = JSON.parse(response["like"]);
like_flag = JSON.parse(response["flag"]);

console.log(like_flag);
  
if(like_flag == 0){  
$(".like-inner-flex-1").toggleClass('like-animate');   
  }else
  $(".like-inner-flex-1").toggleClass('like-animate'); 
  
  if(like_flag){
  $('.like-btn').css({"background-color": "#d629801a" , "outline": 
"none"});
$('.like-inner-flex-1').css({"background-position": "right",  "filter": 
"grayscale(0%)"});

} else {
$('.like-btn').css({"background-color": "transparent", "outline": 
"none"});
$('.like-inner-flex-1').css({"background-position": "right",  "filter": 
"grayscale(100%)"});

}

$("#likes").text(`${like_count}`);
}})
})

..

if I use above script inside the same html file then it works, but in above 
case its not working ?? If there is any work around to do this thing , then 
please suggest me .

Thank you...

 


-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fbb6ae3c-2632-4183-9336-fb6bad5dfe0en%40googlegroups.com.