User validates by clicking a streamlit link

Hi,

I am looking for a way that I can send a user a validation link that, when clicked on in Streamlit, causes an action to be taken. For example:

dear user,

click on this validation link to activate your account.

http://localhost:8501/#validation_link/secretkey

I can figure out how to make a target using an anchor to a header

st.subheader(“validation test”, anchor=“validation_link/secretkey”)

but I’m stuck on how to make clicking the link trigger an action (in this case, setting a database to “confirmed”).

1 Like

Hi @fredzannarbor :wave:

You can wrap any hyperlink via markdown, e.g. have a look at this code where several hyperlinks were added:

import streamlit as st
 
st.markdown(
        "###### Made in [![this is an image link](https://i.imgur.com/iIOA6kU.png)](https://www.streamlit.io/)&nbsp, with :heart: by [@DataChaz](https://www.charlywargnier.com/) &nbsp | &nbsp [![Follow](https://img.shields.io/twitter/follow/datachaz?style=social)](https://www.twitter.com/datachaz) &nbsp | &nbsp [![this is an image link](https://i.imgur.com/thJhzOO.png)](https://www.buymeacoffee.com/cwar05)"
    )

Let me know if that helps?

Best,
Charly

Almost, but not quite! I need to execute some logic based on the fact that the hyperlink was clicked. In Flask this is accomplished by creating a route to receive the confirmation click.

Something like this:

# app/auth/routes.py

from app.auth.email import send_congrats_email

@bp.route('/register', methods=['GET', 'POST'])
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        send_congrats_email(user)
        flash('Check your email for our congrats message')
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', title='Register',
                           form=form)

Maybe all I need to do here is create a target container that holds a form. Will try it.

1 Like

In case this saves someone else some time, this seems to work. I send an email including the URI http://localhost:8501/#validate

          with st.container():
                    st.subheader('Validate', anchor='validate')
                    with st.form(key='form_header'):
                        submit = st.form_submit_button('Validating my email address')
                    if submit:
                        # do database action
                        st.write('Your email has been validated!')

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.