• Skip to primary navigation
  • Skip to main content
FELLOWPRO AG

FELLOWPRO AG

where people work together

  • Products & Services
    • Docbits (Doc² )
    • Digital Transformation
    • Infor OS
    • Ephesoft Transact – IDM Capture
      • FellowKV²-Plugin
      • TableExtraction² Plugin
    • Marketing & CRM
      • SugarCRM
        • Sales & Service
          • Sugar Sell
          • Sugar Serve
          • Business Intelligence – Sugar Discover
        • Marketing
          • Sugar Market
        • Customer Data Management
        • Appointment Calendar
        • Follow-ups
        • Free SugarCRM 30 days trial
      • Oktopost – Social Marketing
      • Sugar Market
  • Customer Success Stories
    • W&H Dentalwerk Launches SugarCRM Platform Worldwide
    • MVTec – SugarCRM for a global manufacturer
    • Bet3000 – SugarCRM for Gambling
    • Coloplast – Mobile CRM for Life Science
    • Diversey – Mobile CRM and Maintenance for Cleaning and Hygiene
    • Diversey – Online Shop implementation
    • Jochen Schweizer – SugarCRM for Leisure
    • Acnos Pharma GmbH streamlines workflow
  • Blog
  • FELLOWPRO
    • About Us
    • Career: We are hiring!
    • Contact Us
    • Partners
  • English
    • Deutsch
  • Show Search
Hide Search

First steps with Python-Flask

Virtual environment

You have to use a virtual environment to manage the dependencies for your project.

Virtual environments are independent groups of Python libraries, one for each project. Packages installed for one project will not affect other projects.

Python 3 is bundled with the venv module to create virtual environments.

Create an environment

Create a new folder and a venv folder within:

$ mkdir pyflask
$ cd pyflask
$ python3 -m venv venv

Windows:

$ py -3 -m venv venv

Activate the environment

Activate the corresponding environment:

$ source venv/bin/activate

Windows:

> venv\Scripts\activate

Install Flask

Flask Logo

Within the activated environment install Flask:

$ pip3 install Flask

Create an applcation

In the earlier created pyflask folder create a file “app.py” and write the code below:

from flask import Flask

app = Flask(__name__)

@app.route("/")
def index ():
    return "Hello World!"

if __name__ == "__main__":
    app.run(debug=True)

To run the application you can either use the flask command or python’s -m switch with Flask. Before you can do that you need to tell your terminal the application to work with by exporting the FLASK_APP environment variable:

$ export FLASK_APP=app.py
$ flask run
Or
$ export FLASK_APP=app.py
$ python -m flask run

In your browser open https://127.0.0.1:5000/ to see your project running:

running project in the browser

Templates

Templates are a good way to have separated web pages. This way you can add your own html templates.

Create a new file called “index.html” and use this code:

<html>
<body>
Hi! Index template here!
</body>
</html>

In your script change following:

from flask import Flask
from flask import render_template

app = Flask(__name__)

@app.route("/")
def index ():
    return render_template("index.html")

if __name__ == "__main__":
    app.run(debug=True)

Next page

Teilen

Python Flask, Python

Additional blogs:

accounting

The future of accounting:

Partnership

The power of partnership

Revolutionary

Revolutionary Efficiency

Food & Beverage

Infor CloudSuite Food & Beverage + DocBits

data

The power of data

  • Contact Us
  • Privacy policy
  • Privacy Preference
  • Imprint
  • AGB