Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

438
Vistas
How to send values from LocalStorage to Flask @app.route()?

Recently, i've been using Flask, but i just wanna ask how to POST data from LocalStorage of the web browser to @app.route

part of main.py

@app.route("/authenticate/post", methods=['GET', 'POST'])
def posting():
  posts = request.form['post']
  return render_template("testing.html", post=posts)

Here i'm making a small web-based "posting and sharing app" just like Instagram, the var posts is the Post Content submitted via textarea of html, and is working perfectly fine. All i need now is how to get the data stored on LocalStorage of a user's browser. Which is the Username of the user. How can i retrieve the Username of the user that is stored on the LocalStorage and do POST request to my @app.route()

Index.html

  <div class="posting">
  <h5>Write Something &amp; Post!</h5>
    <form method="POST" action = "/authenticate/post" autocomplete="off">

<textarea class="books" placeholder="Say something!" id="post" name="post" rows="4" cols="50" maxlength="200"></textarea>
      <br><br>
<input id="enter" type="submit" class="books" value="Post!" onclick="getname()">
    </form>
</div>

The getname() function of my main.js

function getname() {
    let name = localStorage.getItem('username');
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I'd change the submit input to a simple button:

<div class="posting">
  <h5>Write Something &amp; Post!</h5>
    <form id="post-form" method="POST" action = "/authenticate/post" autocomplete="off">
        <input type="hidden" name="username" id="username">

        <textarea class="books" placeholder="Say something!" id="post" name="post" rows="4" cols="50" maxlength="200"></textarea>
        <br><br>
        
        <button type="button" class="books" id="enter" onclick="submitForm()">Post!</button>
    </form>
</div>

Then handle the form submit in JS, while setting a hidden input in the form:

function submitForm()
{
    let name = localStorage.getItem('username');

    // set the value of the hidden input
    document.getElementById("username").value = name;

    // submit the form
    document.getElementById("post-form").submit();
}

OR

You still need the hidden input, but on DOM ready event, you could set the input value:

document.addEventListener('DOMContentLoaded', function() {
    let name = localStorage.getItem('username');

    // set the value of the hidden input
    document.getElementById("username").value = name;
})

This way you can ensure that your "username" will be posted.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda