Git Product home page Git Product logo

fask-tutorial's Introduction

How to run

Generate a new virutal environment

python -m venv venv

Activate the environment

.\venv\Scripts\activate

Install all libraries in requirements.txt

pip install -r .\requirements.txt 

Install DB Schema

flask --app flaskr init-db

Run flask app

flask --app flaskr run

# Run with debug mode
flask --app flaskr run --debug
# ./instance/flaskr.sqlite is generated

Database

SQLITE

SQLite is an embedded SQL database engine. Unlike most other SQL databases, SQLite does not have a separate server process. SQLite reads and writes directly to ordinary disk files.

Tables

Basic database tables are defined in .\flaskr\schema.sql

DROP TABLE IF EXISTS user;
DROP TABLE IF EXISTS post;

CREATE TABLE user
(
    id       INTEGER PRIMARY KEY AUTOINCREMENT,
    username TEXT UNIQUE NOT NULL,
    password TEXT        NOT NULL
);

CREATE TABLE post
(
    id        INTEGER PRIMARY KEY AUTOINCREMENT,
    author_id INTEGER   NOT NULL,
    created   TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    title     TEXT      NOT NULL,
    body      TEXT      NOT NULL,
    FOREIGN KEY (author_id) REFERENCES user (id)
);

DB Explorer

PyCharm Professional

This is the easiest and most intuitive if you have license or student account to use the professional version.

  • Just simply open the sqlite_query.sql, the IDE would suggest you to choose the dialect and configure the Database connection.
  • When got asked to configure the Database, click on the suggestion and browse to your project directory ./instance/flaskr.sqlite
  • Once it is done, you can run your queries and browse all database tables. pycharm pro

DBeaver Community Version

This is the most recommended Database Explorer tool, it is totally free. You can download at DBeaver.

DBeaver

Visual Studio Code

  • Make sure you have VSC installed

  • The extension can be downloaded and install at SQLITE

  • Ctrl+Shift+P: then type SQLITE Query to open a new query editor

  • Open sqlite_query.sql and right-click on the query and select run the selected statement.

  • A result window will be popped up for viewing. sqlite extension

Project Structure

│   .gitignore
│   pyproject.toml
│   README.md
│   requirements.txt
│   sqlite_query.sql
│   tree.txt
│
├───flaskr
│   │   auth.py
│   │   blog.py
│   │   db.py
│   │   schema.sql
│   │   __init__.py
│   │
│   ├───static
│   │       style.css
│   │
│   └───templates
│       │   base.html
│       │
│       ├───auth
│       │       login.html
│       │       register.html
│       │
│       └───blog
│               create.html
│               index.html
│               update.html
│
└───instance
        flaskr.sqlite

fask-tutorial's People

Contributors

simbataisa avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.