You cannot run Django's Python code in JavaScript in a browser. The advice
you have been given applies.

Kind regards,
Sithu


*Sent with Shift
<https://tryshift.com/?utm_source=SentWithShift&utm_campaign=Sent%20with%20Shift%20Signature&utm_medium=Email%20Signature&utm_content=General%20Email%20Group>*

On Mon, Apr 15, 2019 at 10:23 AM sairanganadh Narayana <ssaaii4...@gmail.com>
wrote:

> Thanks for your response. But, I need to run
> ORM(model.objects.filter(pk=1)) commands in javascript and show results in
> HTML pages. I was wrong in question. Please suggest any possibility.
>
>
> On Tuesday, April 9, 2019 at 5:51:24 PM UTC+5:30, Robin Riis wrote:
>>
>> in models.py you can define a 'as_json' function
>>
>> def as_json(self):
>>     return dict(
>>         identification_number = self.id
>>         awesome_picture = self.picture
>>     )
>>
>> in views.py:
>>
>> class My_View(View):
>>     def get(self, request):
>>         if request.is_ajax():
>>             q = request.GET.get('q', '')
>>             answer = model.objects.get(pk=q)
>>             if not answer:
>>                 this_answer = dict()
>>                 this_answer['results'] = 'did not find anything'
>>                 return JsonResponse(this_answer)
>>             this_answer = [d.as_json() for d in answer]
>>             return HttpResponse(json.dumps(this_answer,
>> content_type='application/json')
>>         else:
>>             this_answer = dict()
>>             this_answer['not_allowed'] = 'you are not allowed here.'
>>             return HttpResponse(this_answer,
>> content_type='application/json')
>>
>> hope this helps!
>>
>> Den tis 9 apr. 2019 kl 13:30 skrev sairanganadh Narayana <
>> ssaai...@gmail.com>:
>>
>>> I'm trying to get run model.objects.filter(id=2) from javascript and
>>> show on database. I am unable to get solution for this. Please guide me
>>> solution for this or alternative for this.
>>>
>>> --
>>> 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...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/569ce414-b717-4348-a688-b92904036864%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/569ce414-b717-4348-a688-b92904036864%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/500cbb0e-5c0a-4f23-a777-302f8671baa1%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/500cbb0e-5c0a-4f23-a777-302f8671baa1%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAH-SnCBjym_OYH%3D%2BnhJU%2BmKG3ydgyCbDMr7t0uabSUEAqpBzuw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to