Python Forum
how i save the html form to flask database
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how i save the html form to flask database
#1
I need help.
I want to this input area save the flask database.
how i save the html form to flask?

https://hizliresim.com/grrMm5

https://hizliresim.com/P11JX5
Reply
#2
(Feb-06-2019, 08:50 PM)mebaysan Wrote: how i save the html form to flask?
The page you have is messy,i guess it's a tempalte you use.
Nothing wrong with that,but when learn this is has a lot stuff that is confusing,as this form is setup to use ajax-request.
Do you know how a basic form work in HTML?

To take out the form out of site and make it work Pen.
You see that it work and i have put in action="#" method="POST".
# is just so that it work on CodePen.
action name is what you call function on server side Flask.
name="comment_content"(<input>) get send when push Submit.

To show this setup in Flask.
The stander and best way for DB in Flask is to use Flask-SQLAlchemy.
app.py:
from flask import Flask, render_template, jsonify, request
 
app = Flask(__name__)
@app.route('/')
def index():
   return render_template("index.html")
 
@app.route('/my_form', methods=['POST'])
def my_form():
    form_input = request.form['comment_content']
    # Now that get value back to server can send it to a DB(use Flask-SQLAlchemy)
    return(form_input)

if __name__ == '__main__':
   app.run(debug=True)
index.html:
<!doctype html>
<html>
  <head>
    <title>Some title</title>
    <link rel=stylesheet type=text/css href="{{ url_for('static', filename='css/style.css') }}" />
  </head>
  <body>
    <div id="start">
      <h1>Start page</h1>

      <form action="{{ url_for('my_form') }}" method='POST'>
        <div>
          <textarea id="comment_content" name="comment_content"></textarea>
          <span class="character-counter" ></span></div>
        <div>
          <button type="submit" class="btn waves-effect waves-light">GÖNDER</button>
        </div>
      </form>

    </div>
  </body>
</html>
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Flask - use bootstrap styles in HTML Krayna 1 1,006 Aug-29-2023, 02:33 PM
Last Post: menator01
  Flask: sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) database is locked pythonpaul32 1 2,032 Apr-04-2023, 07:44 AM
Last Post: Larz60+
  Flask and SQLAlchemy question: Database is being created but tables aren't adding pythonpaul32 3 4,418 Feb-07-2023, 10:48 AM
Last Post: pythonpaul32
  Flask/non-flask database sharing MorganSamage 2 1,136 Feb-03-2023, 12:05 PM
Last Post: MorganSamage
  Flask: editing a submitted form test 1 1,703 Jun-07-2022, 10:37 AM
Last Post: test
  Save JSON data to sqlite database on Django Quin 0 2,804 Mar-26-2022, 06:22 PM
Last Post: Quin
  Post HTML Form Data to API Endpoints Dexty 0 1,382 Nov-11-2021, 10:51 PM
Last Post: Dexty
  show csv file in flask template.html rr28rizal 8 34,532 Apr-12-2021, 09:24 AM
Last Post: adamabusamra
  HTML multi select HTML listbox with Flask/Python rfeyer 0 4,536 Mar-14-2021, 12:23 PM
Last Post: rfeyer
  Flask Basics request.form ifigazsi 0 1,783 Feb-09-2021, 09:05 AM
Last Post: ifigazsi

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020