Giter Site home page Giter Site logo

flask-doc's Introduction

Flask-documentation

what is flask:.

Flask is a web framework, it’s a Python module that lets you develop web applications easily. It’s has a small and easy-to-extend core, it’s a microframework Flask is a web application framework written in Python Unlike the Django framework, Flask is very Pythonic. It’s easy to get started with Flask, because it doesn’t have a huge learning curve.

Requirement---------------------------------------

1-) Python Version:

We recommend using the latest version of Python. Flask supports Python 3.6 and newer.

2-) other Dependencies distributions will be installed automatically when installing Flask:

  • Werkzeug
  • Jinja
  • MarkupSafe
  • ItsDangerous
  • Click

Installation---------------------------------------------

1-) install python:

in windows----------

get the latest python version for windows 64 and then you need to install it.

check the python version it should be (Python 3.10.0):
python -V

in linux-------------

sudo apt-get install python3.10
check the python version it should be (Python 3.10.0):
python3 -V

2-) use virtual enviroment:

to start our project its recommended to use virtual enviroment to manage the dependencies for your project, both development and in production. Virtual environments are independent groups of Python libraries, one for each project. Packages installed for one project will not affect other projects or the operating system’s packages. Python comes bundled with the venv module to create virtual environments.

Create an environment:

Create a project folder and a venv folder within:

in windows CMD ----------

mkdir myproject
cd myproject
py -3 -m venv .venv

in linux BASH -------------

mkdir myproject
cd myproject
python3 -m venv .venv

Activate the environment:

in windows----------

.venv\Scripts\activate

in linux-------------

source .venv/bin/activate

Your shell prompt will change to show the name of the activated environment(venv).

3-) Install Flask:

pip install Flask

Flask is now installed, in the python and we can use it by export it in the python comand.

4-) creat a file in our folder and name it as app.py

open CMD and create afile with vs code

code app.py

First we imported the Flask class. An instance of this class will be our WSGI application.

from flask import Flask, render_template

Next we create an instance of this class. The first argument is the name of the application’s module or package. name is a convenient shortcut for this that is appropriate for most cases. This is needed so that Flask knows where to look for resources such as templates and static files.

app = Flask(__name__)

We then use the route() decorator to tell Flask what URL should trigger our function. and function called index with to render the index.html flie.

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


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

then create a template folder, add new file in template and name it as "index.html" and wirte inside of it our code:

write in the terminal (CMD or BASH):

mkdir templates
cd templates
code index.html 

wirte a test code in the index file such like:

<h1> this is the test code </h1>

5-) start up the server:

in windows CMD----------

cd ..
flask run

in linux BASH-------------

cd ..
flask run

now the server is runing go to the browser and follow the link:

http://127.0.0.1:5000/

flask-doc's People

Contributors

shamsmikdad 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.