I am new to websocket so I have some problems. I'm trying to create a web based user interface, where the user will press the button and start the script in the background and user is redirectet to display_console_output, where data will be displayed. I would like to display console output in the browser in real time. I am able to display the output when the script finished her job, and I do not know how to display data if script is working. Here is my code
views.py:
def display_console_output(request):
if request.method == 'GET':
process = subprocess.Popen('ping -t 8.8.8.8', shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
output = process.communicate()[0]
return render(request, 'update_file/display_console_output.html', {'page_title': 'Console Output',
'console_output': (output.decode('utf-8')),})
routing.py:
application = ProtocolTypeRouter({
# Empty for now (http->django views is added by default)
'websocket': AllowedHostsOriginValidator(
AuthMiddlewareStack(
URLRouter(
[
url(r"^(?P<consoleOutput>[\w.@+-]+)/$", ConsoleDataConsumer),
]
)
)
)
})
I will appreciate if you can give me any advice how to solve my problem..