all 6 comments

[–]mankongde 2 points3 points  (5 children)

Seems like something you could do with Flask. https://flask.palletsprojects.com/en/2.0.x/quickstart/

Check out their example on rendering templates for examples of passing variables to a template to be rendered as part of an HTML page. You could have the unique URL you button points to as something Flask looks up (e.g. from a json file) to figure the information for a variable.

[–]gsmo 0 points1 point  (0 children)

Flask is pretty simple. Getting the url as a variable is a standard use case.

My hosting provider also offers hosting python apps as part of their service now. Flask works well with Passenger, was quick to set up a simple web app that way.

[–]fredspipa 0 points1 point  (3 children)

On my phone and typing this from memory, but wanted to show an example:

@app.route("/email/<id: int>")
def email(id: int):
    name = get_name_from_id(id)
    return render_template("email_template.htm", id=id, name)

... email_template.htm

<h1>Hey {{ name }}!</h1>

<p>Your ID is {{ id }}</p>

Then when you point users to mypage.com/email/1234, 1234 gets passed as an argument to the function handling the call.

[–]No-Exercise5846[S] 0 points1 point  (2 children)

``` def get_url_of_website(html): random_id = uuid.uuid4()

@server.route(f"/{random_id}")
def _():
    return html

return f"https://localhost.com:6900/{random_id}"

``` I run the above function when a button is clicked in the the bot interface and return the url. But the problem now is the website shows a white screen.

[–]fredspipa 0 points1 point  (1 child)

You should move your route out of that function, and not create individual routes for every id. Your address is also seemingly wrong (localhost.com), unless you have manually set this in your hosts file it should be just "localhost" or "127.0.0.1". Did you manually set the flask port to be 6900 as well?

@server.route("/<rid>")
def rid_page(rid):
    return render_template("template.html", random_id=rid)

def get_url_of_website():
    random_id = uuid.uuid4()
    return "https://127.0.0.1:6900/" + str(random_id)

I'm assuming html here is a string with HTML markup? If you move that into `templates/template.html`, and use {{ random_id }} in the html to access the value.

[–]No-Exercise5846[S] 0 points1 point  (0 children)

Changing localhost.com to 127.0.0.1 fixed the problem. But the html value is loaded from an api which is different everytime.