Set up flask demo with open source project

今天的工作,老板终于要让我做CI了好感动。

###Clone the project and set up virtual environment

  • Choose a workspace to place the project

    1
    2
    3
    4
    5
    6
    7
    $ mkdir gitlab
    $ cd mkdir
    $ gcl https://gitlab.com:cecid/microblog.git
    $ cd microblog
  • Set the virtual environment

    1
    2
    3
    4
    5
    6
    7
    $ python3 -m venv flask
    $ source flask/bin/activate
    $ flask/bin/pip install --upgrade pip
    $ flask/bin/pip install flask flask-login flask-openid flask-mail flask-sqlalchemy flask-whooshalchemy flask-wtf flask-babel guess_language-spirit flipflop coverage tempita decorator gunicorn pbr six speaklater sqlalchemy-migrate flask-uploads pyenchant

Database connection

Connect mysql with python
  • pip install pymysql
  • Modify config.py
    SQLALCHEMY_DATABASE_URI = 'mysql+pymysql:///username:password@localhost/databasename'
  • run $ python db_create.py
Add user
  • Add user admin whose password is admin

    1
    2
    3
    4
    5
    $ flask/bin/python
    >> from microblog import db,models
    >> u = models.User(username='admin',email='email@email.com',password='admin')
    >> db.session.add(u)
    >> db.session.commit()

###Set the website can be visited from other hosts

  • Modify run.py from app.run(debug=debug) to app.run(host='0.0.0.0',debug=debug)

Run the server

  • Under the path gitlab/microblog, run python run.py