S
S
shibanovan2018-06-22 06:07:02
Python
shibanovan, 2018-06-22 06:07:02

How to copy to clipboard in flask?

I am slowly learning web programming, twisting Flask. I came up with a project - a site parser. By clicking on the button, you need to call a function that will parse the site and copy the text to the clipboard. Let's take the simplest code as an example:

from flask import Flask, request

app = Flask(__name__)


@app.route("/")
def hello():
    return '<form action="/echo" method="GET"><input name="text"><input type="submit" value="Echo"></form>'


@app.route("/echo")
def echo():
    return '<form action="/echo" method="GET"><input name="text"><input type="submit" value="Echo"></form>' +\
           "You said: " + request.args.get('text', '')



if __name__ == "__main__":
    app.run()

Tell me, how can I copy the treasured string 'text' to the client into the buffer? As far as I understand, the standard methods will not work, since the Python code is executed on the server. Do I need to somehow get out through js? Can you show a simple example?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2018-06-22
@immaculate

That's right, Flask runs on the server side. You need an HTML template in which the necessary text will be displayed, and a button, upon pressing which the text will be copied using Javascript. For example, with clipboardjs .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question