GithubHelp home page GithubHelp logo

abalarin / flask-on-linode Goto Github PK

View Code? Open in Web Editor NEW
22.0 1.0 28.0 65 KB

Deploying Flask App on Linode

Home Page: http://172.104.28.209/

Python 34.05% JavaScript 0.42% CSS 9.39% HTML 56.15%
python flask linode

flask-on-linode's Introduction

Simple Flask CRUD Web Application

This is a very simple Flask Application where user can log in and create posts.

Application Breakdown

This is the breakdown of a fairly simple Flask Application using a SQLite database

Flask-on-Linode
│   README.md
│   FlaskDeployment.md
│   .gitignore
│
└───flask_app
│   │   __init__.py
│   │   forms.py
│   │   models.py
│   │   routes.py
│   │   requriments.txt
│   │   site.db
│   │
│   └───static
│   │   │   ...
│   │
│   └───templates
│   │   │   ...

Flask Frameworks

These are the Flask libraries used in this Project. You'll find these in the requirements.txt file.

Deploying Locally

Lets walk through setting up your development environment and deploying this application on your local machine

  1. Install Python, pip, and virtualenv
  1. Clone this repo and CD into the projects directory
git clone https://github.com/abalarin/Flask-on-Linode.git flask_app_project
cd flask_app_project
  1. Create and activate a virtualenv
virtualenv venv
source venv/bin/activate
  1. Install packages
pip install -r flask_app/requirements.txt
  1. Create Flask environment variables
export FLASK_APP=flask_app/__init__.py
export FLASK_ENV=development
  1. Run it
flask run

Next Steps

flask-on-linode's People

Contributors

abalarin avatar leslitagordita avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

flask-on-linode's Issues

Fails in Linode Marketplace on Debian 9 due to incompatible Python and Flask-WTF versions

Hoping this is the right place to mention this (I could not find Flask-on-Linode on https://github.com/linode/Marketplace-Apps, for example)

I've had some trouble diagnosing 502s I get out of the box when installing through Linode Marketplace, although it comes with the correct configuration as described here.

After much confusion I realised the reason is the flask server is constantly getting restarted after failing with:

$ cat /var/log/flask_app/flask_app.err.log

SyntaxError: invalid syntax
[2021-07-24 23:42:51 +0000] [19401] [INFO] Worker exiting (pid: 19401)
/usr/local/lib/python3.5/dist-packages/flask_sqlalchemy/__init__.py:873: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True or False to suppress this warning.
  'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and '
[2021-07-24 23:42:51 +0000] [19402] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/gunicorn/arbiter.py", line 557, in spawn_worker
    worker.init_process()
  File "/usr/lib/python3/dist-packages/gunicorn/workers/base.py", line 126, in init_process
    self.load_wsgi()
  File "/usr/lib/python3/dist-packages/gunicorn/workers/base.py", line 136, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/lib/python3/dist-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/lib/python3/dist-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/usr/lib/python3/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/lib/python3/dist-packages/gunicorn/util.py", line 384, in import_app
    __import__(module)
  File "/home/flask_app_project/flask_app/__init__.py", line 14, in <module>
    from flask_app import routes
  File "/home/flask_app_project/flask_app/routes.py", line 7, in <module>
    from flask_app.forms import PostForm
  File "/home/flask_app_project/flask_app/forms.py", line 1, in <module>
    from flask_wtf import FlaskForm
  File "/usr/local/lib/python3.5/dist-packages/flask_wtf/__init__.py", line 1, in <module>
    from .csrf import CSRFProtect, CsrfProtect
  File "/usr/local/lib/python3.5/dist-packages/flask_wtf/csrf.py", line 220
    dest = f'{view.__module__}.{view.__name__}'

The reason is that the installed version of Flask-WTF uses f-syntax for strings (f'Here's the value of {something}'), which came in in Python 3.6.

$ pip freeze | grep WTF
Flask-WTF==0.15.0
WTForms==2.3.3
$ python3 --version
Python 3.5.3

0.15 has officially dropped support for 3.5 (wtforms/flask-wtf#416) and the very next release (0.15.1) adds a python_requires to disallow installation on 3.5: https://flask-wtf.readthedocs.io/en/0.15.x/changes/#version-0-15-1

Possible fixes would be:

  • Upgrading python to 3.6. The Linode marketplace suggests this app with Debian 9 only, where python 3.6 doesn't seem to be included out-of-the-box (apt-cache search python3 | grep 3.6 shows no results). I'm not sure where this is set up for the standard server that comes up via Linode Marketplace?
  • Downgrading Flask-WTF by explicitly requiring Flask-WTF<0.15.0 in requirements.txt (I've tested this and it works)

On an entirely separate note, may I suggest an addition to the otherwise great deployment notes on allowing incoming TCP traffic from ufw via something like ufw allow from <your-ip> to <linode-ip> proto tcp port 80? This is not entirely obvious to noobs like me.

Thanks for the nice example app and detailed explanation on setting it up.

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.