Hello. Want to get started with Flask quickly? Good. You came to the right place. This Flask application framework is pre-configured with Flask-SQLAlchemy, Flask-WTF, Fabric, Coverage, and the Bootstrap frontend (among others). This will get your Flask app up and running on Heroku or PythonAnywhere quickly. Use this starter, boilerplate for all you new Flask projects. Cheers!
Preview the skeleton app here - http://www.flaskboilerplate.com/
- Clone the repo
$ git clone https://github.com/realpython/flask-boilerplate.git
$ cd flask-boilerplate
- Initialize and activate a virtualenv:
$ virtualenv --no-site-packages env
$ source env/bin/activate
- Install the dependencies:
$ pip install -r requirements.txt
- Run the development server:
$ python app.py
- Navigate to http://localhost:5000
If you plan on working exclusively within PythonAnywhere, which you can, because it provides a cloud solution for hosting and developing your application, you can skip step one entirely. :)
- Sign up for PythonAnywhere, if you haven't already
- Once logged in, you should be on the Consoles tab.
- Clone this repo:
$ git clone git://github.com/realpython/flask-boilerplate.git
$ cd flask-boilerplate
- Create and activate a virtualenv:
$ virtualenv venv --no-site-packages
$ source venv/bin/activate
- Install requirements:
$ pip install -r requirements.txt
- Next, back on PythonAnywhere, click Web tab.
- Click the "Add a new web app" link on the left; by default this will create an app at your-username.pythonanywhere.com, though if you've signed up for a paid "Web Developer" account you can also specify your own domain name here. Once you've decided on the location of the app, click the "Next" button.
- On the next page, click the "Flask" option, and on the next page just keep the default settings and click "Next" again. Once the web app has been created (it'll take 20 seconds or so), you'll see a link near the top of the page, under the "Reload web app" button, saying "It is configured via a WSGI file stored at..." and a filename. Click this, and you get to a page with a text editor.
- Then update the following lines of code:
from
project_home = u'/home/your-username/mysite'
to
project_home = u'/home/your-username/flask-boilerplate'
from
from flask_app import app as application
to
from app import app as application
- Save the file.
- Back on the Web tab, scroll down to the "Virtualenv" section, and click on the "Enter path to a virtualenv, if required" link. In the input that pops up, enter
/home/your-username/flask-boilerplate/venv
(changing "your-username" appropriately) and hit return. - Click the green "Reload" button at the top of the page.
- Go to the website http://your-username.pythonanywhere.com/ (or your own domain if you specified a different one earlier), and you should see something like this - http://www.flaskboilerplate.com/.
Now you're ready to start developing!