Snippets Collections
import threading

@app.route('/long-task')
def long_task():
	threading.Thread(target=do_long_task).start()
	return "Task started"
@app.route('/long-task')
def long_task():
	do_long_task()
	return "Task completed"
myapp
|
|--app
|    |--main
|    |    |--__init__.py
|    |    |--main.py
|    |
|    |--auth
|    |    |--__init__.py
|    |    |--auth.py
|    |
|    |--__init__.py
|    |--errors.py
|    |--models.py
|    |-- templates/
|    |--static/
|
|--tests/
|--config.py
|--myapp.py
|--requirements.txt
ecommerce/
|
├── static/
|   ├── logo.png
|   ├── main.css
|   ├── generic.js
|   └── product_view.js
|
├── templates/
|   ├── login.html
|   ├── forgot_password.html
|   ├── signup.html
|   ├── checkout.html
|   ├── cart_view.html
|   ├── index.html
|   ├── products_list.html
|   └── product_view.html
|
├── app.py
├── config.py
└── models.py
<!doctype html>
<html>
<head>
    <title>Home page</title>
    </head>
    <body>
	{% if content == "true" %}
            <p>True!</p>
        {% else %}
            <p>False :(</p>
        {% endif %}
    </body>
</html>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>{% block title %}{% endblock %}</title>
        <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='site.css')}}" />
    </head>

    <body>
        <div class="navbar">
            <a href="{{ url_for('home') }}" class="navbar-brand">Home</a>
            <a href="{{ url_for('about') }}" class="navbar-item">About</a>
            <a href="{{ url_for('contact') }}" class="navbar-item">Contact</a>
        </div>

        <div class="body-content">
            {% block content %}
            {% endblock %}
            <hr/>
            <footer>
                <p>© 2018</p>
            </footer>
        </div>
    </body>
</html>

export FLASK_ENV=development                         

export FLASK_ENV=production 

FLASK_APP=hello.py flask run






If you have installed many dependencies in your system and you need requirements.txt for a specific project, you can install first pipreqs:

$ pip install pipreqs

and execute the below command under the project folder.

$ pipreqs

This command will generate requirements.txt file for the particular project.
from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"
from flask import Flask,render_template,request, redirect
 
 
app = Flask(__name__)
app.config['SECRET_KEY'] = 'dajdsjas'
 
 
@app.route('/home')
def home():
    return 'Home page'
 
 
 
@app.route('/take_parameter', methods = ["POST"])
def takeparam():
    try:
        pas = request.args(silent=True)
        #app.logger.info(json)
        return 'OK'
    except:
        return 'INTERNAL ERROR', 500
    
 
@app.route('/take_json', methods = ["POST"])
def takejson():
    try:
        pas = request.get_json(silent=True)
        #app.logger.info(json)
        return 'OK'
    except:
        return 'INTERNAL ERROR', 500
    
if __name__ =='__main__':
    app.run(debug=True)
 
star

Tue Feb 22 2022 15:40:56 GMT+0000 (UTC)

#flask #python
star

Tue Feb 22 2022 15:37:55 GMT+0000 (UTC)

#flask #python
star

Fri Dec 10 2021 17:11:35 GMT+0000 (UTC) https://dev.to/blankgodd/creating-a-blueprint-based-flask-app-199h

#flask
star

Fri Dec 10 2021 17:03:04 GMT+0000 (UTC) https://realpython.com/flask-blueprint/

#flask
star

Thu Dec 09 2021 18:07:50 GMT+0000 (UTC) https://www.techwithtim.net/tutorials/flask/html-templates/

#flask
star

Thu Dec 09 2021 17:50:06 GMT+0000 (UTC) https://code.visualstudio.com/docs/python/tutorial-flask

#flask
star

Sun Jun 27 2021 14:09:50 GMT+0000 (UTC) https://stackoverflow.com/questions/31252791/flask-importerror-no-module-named-flask

#python #flask
star

Sun Jun 27 2021 14:09:38 GMT+0000 (UTC) https://stackoverflow.com/questions/31252791/flask-importerror-no-module-named-flask

#python #flask
star

Thu Oct 22 2020 09:00:37 GMT+0000 (UTC)

#python #flask
star

Wed May 13 2020 18:55:25 GMT+0000 (UTC) https://www.youtube.com/watch?v=zdgYw-3tzfI

#flask

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension