The above query will create a table in the Database with name MyUsers, now copy the following code and paste in app.python file.įrom flask import Flask, render_template, requestĬur.execute("INSERT INTO MyUsers(firstName, lastName) VALUES (%s, %s)", (firstName, lastName)).To create a table use the below query:ĬREATE TABLE MyUsers ( firstname VARCHAR(30) NOT NULL, lastname VARCHAR(30) NOT NULL) Now we’ve developed our form, the next step is database connection.Upon running the above code you must get the page as below.Modify our app.python file and add the below code in it.To do this create a folder named Templates inside it create a file index.html and copy the below code. Now you need to create a simple HTML page with two text field First Name, Last Name and submit button. Simply we’re routing out request and displaying “Hello Nuclear Geeks”, On running the following program type on your browser to see the output!! “Hello Nuclear Geeks” If you’ve gone through Python web services using Flask you would understand 100% of the above code. Open P圜harm, create new Python file name app.python and type the below code into your app.python file.To get started you’ll be needing any IDE I’ll be using P圜harm,MySQL DB and that’s it!!! This tutorial, unlike my earlier posts will be steps depicting what and how to do…. This tutorial is completely made for beginner, So the prerequisite of this tutorial is going to be minimum only thing which I will personally recommend it to have a high level overview of Python web services using Flask and have minimum understanding of SQL and Database set up. IN THIS TUTORIAL WE’RE GOING TO LEARN HOW TO CONNECT FLASK TO MYSQL DATABASE AND YOU CAN INSERT THE FORM DATA. If you followed my previous tutorial Python web services using Flask you must be aware on how to create your own REST services, GET and POST the data.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |