Flask Quickstart

code:

# coding: utf-8

import logging
from flask import Flask


app = Flask(__name__)


@app.route('/')
def index():
    logging.info("here is index")
    return "<span style='color:red'>I am app 1</span>"


def main():
    app.run('*', '8080')


if __name__ == '__main__':
    main()

Development Server

$ python3 main.py

$ curl localhost:8080
<span style='color:red'>I am app 1</span>%

uWsgi

uwsgi.ini:

[uwsgi]
socket = 127.0.0.1:9090
wsgi-file = main.py
callable = app
processes = 4
threads = 2
stats = 127.0.0.1:9191

Nginx:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    # SSL configuration
    #
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    #
    # Note: You should disable gzip for SSL traffic.
    # See: https://bugs.debian.org/773332
    #
    # Read up on ssl_ciphers to ensure a secure configuration.
    # See: https://bugs.debian.org/765782
    #
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    #
    # include snippets/snakeoil.conf;

    root /var/www/html;

    # Add index.PHP to the list if you are using PHP
    index index.html index.htm index.Nginx-debian.html;

    server_name _;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.

        uwsgi_pass 127.0.0.1:9090;
        include uwsgi_params;

        try_files $uri $uri/ =404;
    }

    # pass PHP scripts to FastCGI server
    #
    #location ~ \.PHP$ {
    #   include snippets/fastcgi-PHP.conf;
    #
    #   # With PHP-fpm (or other unix sockets):
    #   fastcgi_pass unix:/var/run/PHP/PHP7.4-fpm.sock;
    #   # With php-cgi (or other tcp sockets):
    #   fastcgi_pass 127.0.0.1:9000;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with Nginx's one
    #
    #location ~ /\.ht {
    #   deny all;
    #}
}

$ uwsgi --ini uwsgi.ini

$ curl localhost
<span style='color:red'>I am app 1</span>%

相关文章

Jinja2:是Python的Web项目中被广泛应用的模板引擎,是由Pyt...
监听QQ消息并不需要我们写代码,因为市面上已经有很多开源QQ...
【Flask框架】—— 视图和URL总结
python+web+flask轻量级框架的实战小项目。登录功能,后续功...
有了这个就可以配置可信IP,关键是不需要企业认证,个人信息...