/flask-sql

A sample web application project demonstrating the use of Flask (a light-weight Python web framework), SQLite, and SQLAlchemy (Python object-relational mapping library)

Primary LanguagePython

Flask Web Application Development

Environments

  • Development Environment: notebooks.ai
  • Production Environment: pythonanywhere.com
  • Source Code Repository: GitHub (this repo)

Components

  • Flask
  • sqlite3
  • flask_sqlalchemy

References:

Steps

  1. To install flask

$pip install -U Flask

  1. To install -U flask_sqlalchemy
  • $pip install -U flask_sqlalchemy
  • "-U" = "--updates"
  1. To combine 1 and 2 into a single requirements.txt file The requirements.txt file contains two simple lines:
flask
flask_sqlapchemy

$install -r requirements.txt

  1. to Run flask
  • $export FLASK_APP="/app/webapps/hello/hello.py"

  • $flask run

sqlite3 on Ubuntu

  1. How to install sqlite3 on ubuntu?

$apt-get install sqlite3 libsqlite3-dev or

$sudo apt-get install sqlite3 libsqlite3-devif you are not admin/root

  1. How to create a new database?

$sqlite3 dbname.db

This will take you to sqlite3 interactive shell sqlite>

  • sqlite>.help for help
  • sqlite3>.quit to exit
  • sqlite>.read myscript.sql to run a SQL script
  • sqlite>select * from cities; to run a query
  1. How to connect to an existing DB?

$sqlite3 dbname.db

or

$sqlite3 then sqlite>.open dbname.db

Installation

  1. on Windows, open git bash shell
  2. $ssh das10
  3. $cd pythonwork
  4. $git clone https://github.com/wcj365/flask-sql.git
  5. $cd flask-sql
  6. $python3 -m venv venv
  7. $source venv/bin/activate
  8. (venv)$pip install -r requirements.txt