# How can I use django to call a python script and return the result in realtime?

**URL:** <https://forum.djangoproject.com/t/how-can-i-use-django-to-call-a-python-script-and-return-the-result-in-realtime/14644>\
**Category:** Getting Started\
**Created:** [July 6, 2022, 3:44am UTC](https://forum.djangoproject.com/t/how-can-i-use-django-to-call-a-python-script-and-return-the-result-in-realtime/14644 "2022-07-06T03:44:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![grodrigues2021](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/grodrigues2021/32/9158_2.png) [@grodrigues2021](https://forum.djangoproject.com/u/grodrigues2021)\
**Post date:** [July 6, 2022, 3:44am UTC](https://forum.djangoproject.com/t/how-can-i-use-django-to-call-a-python-script-and-return-the-result-in-realtime/14644/1 "2022-07-06T03:44:27Z")

</div>

HI everyone, I’m new in django and I don’t know how to get some result from my python scrip and show in web page, I think that can be done with django but I don’t know how.

Example:

test.py:

X = 1+1  
print(var)

How can i get X in django?

---

<div class="post-metadata">

**Author:** ![oneflydown](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/oneflydown/32/9123_2.png) [@oneflydown](https://forum.djangoproject.com/u/oneflydown)\
**Post date:** [July 6, 2022, 4:41am UTC](https://forum.djangoproject.com/t/how-can-i-use-django-to-call-a-python-script-and-return-the-result-in-realtime/14644/2 "2022-07-06T04:41:03Z")

</div>

Start here

[Writing your first Django app](https://docs.djangoproject.com/en/4.0/intro/tutorial01/)

---

<div class="post-metadata">

**Author:** ![grodrigues2021](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/grodrigues2021/32/9158_2.png) [@grodrigues2021](https://forum.djangoproject.com/u/grodrigues2021)\
**Post date:** [July 6, 2022, 9:55am UTC](https://forum.djangoproject.com/t/how-can-i-use-django-to-call-a-python-script-and-return-the-result-in-realtime/14644/3 "2022-07-06T09:55:31Z")

</div>

I’ve read about views, models, urls…etc but I can’t find anything explaining how to use my python scripts that I usually use on a daily basis to create my RPA automations, how I pass the variables of my scripts external to django, like this simple test.py that I showed, how do I see variables from test.py or how do I pass variables to test.py?

---

<div class="post-metadata">

**Author:** ![leandrodesouzadev](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/leandrodesouzadev/32/8981_2.png) [@leandrodesouzadev](https://forum.djangoproject.com/u/leandrodesouzadev)\
**Post date:** [July 6, 2022, 10:40am UTC](https://forum.djangoproject.com/t/how-can-i-use-django-to-call-a-python-script-and-return-the-result-in-realtime/14644/4 "2022-07-06T10:40:08Z")

</div>

This is not related to django, but with python itself.  
With you want to use a script, turn it into a function, import it when you want to use it and then use the result.

---

<div class="post-metadata">

**Author:** ![grodrigues2021](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/grodrigues2021/32/9158_2.png) [@grodrigues2021](https://forum.djangoproject.com/u/grodrigues2021)\
**Post date:** [July 6, 2022, 12:23pm UTC](https://forum.djangoproject.com/t/how-can-i-use-django-to-call-a-python-script-and-return-the-result-in-realtime/14644/5 "2022-07-06T12:23:40Z")

</div>

Opa beleza leandro? com esse nome imagino que seja Brasileiro kkkkk Entendi, vou ver direitinho como vou fazer , eu pensei no caso de eu ter varios scripts, eu poderia apenas pegar o retorno de dentro deles, mas faz sentido transformar eles em funções.

---

<div class="post-metadata">

**Author:** ![leandrodesouzadev](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/leandrodesouzadev/32/8981_2.png) [@leandrodesouzadev](https://forum.djangoproject.com/u/leandrodesouzadev)\
**Post date:** [July 6, 2022, 12:25pm UTC](https://forum.djangoproject.com/t/how-can-i-use-django-to-call-a-python-script-and-return-the-result-in-realtime/14644/6 "2022-07-06T12:25:09Z")

</div>

Yeah, i’m Brazilian too!  
Good luck buddy!
