Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 580b112

Browse files
committed
Python Web Flask Deploy
1 parent c12b319 commit 580b112

File tree

8 files changed

+124
-0
lines changed

8 files changed

+124
-0
lines changed

‎day-130/myproject/__init__.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from flask import Flask
2+
from .config import config
3+
4+
def create_app(config_name='default'):
5+
app = Flask(__name__)
6+
app.config.from_object(config[config_name])
7+
config[config_name].init_app(app)
8+
9+
@app.route("/")
10+
def index():
11+
return "Hello world!"
12+
13+
return app
549 Bytes
Binary file not shown.
2.43 KB
Binary file not shown.

‎day-130/myproject/config.py‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import os
2+
import logging
3+
4+
class Config:
5+
## 管理员邮件
6+
MAIL_USERNAME = 'username'
7+
MAIL_PASSWORD = 'Pa$sw0rd'
8+
MAIL_USE_TLS = True
9+
MAIL_SERVER = 'smtp.163.com'
10+
MAIL_PORT = '465'
11+
FLASKY_MAIL_SENDER = 'flaskyserver@163.com'
12+
FLASKY_ADMIN = 'flaskyadmin@163.com'
13+
FLASKY_MAIL_SUBJECT_PREFIX = '服务器又挂啦'
14+
LOG_FILENAME = 'flasky.log'
15+
16+
@staticmethod
17+
def init_app(app):
18+
pass
19+
20+
21+
class DevelopmentConfig(Config):
22+
DEBUG = True
23+
24+
@classmethod
25+
def init_app(cls, app):
26+
super().init_app(app)
27+
28+
29+
class TestingConfig(Config):
30+
TESTING = True
31+
@classmethod
32+
def init_app(cls, app):
33+
super().init_app(app)
34+
35+
formatter = logging.Formatter('%(asctime)s - %(threadName)s - %(levelname)s - [line:%(lineno)d] - %(funcName)s - %(message)s')
36+
file_handler = logging.FileHandler(cls.LOG_FILENAME, mode='a', encoding='utf-8', delay=False)
37+
file_handler.setLevel(logging.DEBUG)
38+
file_handler.setFormatter(formatter)
39+
40+
app.logger.addHandler(file_handler)
41+
42+
43+
class ProductionConfig(Config):
44+
@classmethod
45+
def init_app(cls, app):
46+
super().init_app(app)
47+
48+
from logging.handlers import SMTPHandler
49+
50+
credentials = None
51+
secure = None
52+
53+
if getattr(cls, 'MAIL_USERNAME', None):
54+
credentials = (cls.MAIL_USERNAME, cls.MAIL_PASSWORD)
55+
if getattr(cls, 'MAIL_USE_TLS', None):
56+
secure = ()
57+
mail_handler = SMTPHandler(
58+
mailhost=(cls.MAIL_SERVER, cls.MAIL_PORT),
59+
fromaddr=cls.FLASKY_MAIL_SENDER,
60+
toaddrs=[cls.FLASKY_ADMIN],
61+
subject=cls.FLASKY_MAIL_SUBJECT_PREFIX + ' APPLICATION ERROR',
62+
credentials=credentials,
63+
secure=secure
64+
)
65+
mail_handler.setLevel(logging.ERROR)
66+
app.logger.addHandler(mail_handler)
67+
68+
config = {
69+
'development': DevelopmentConfig,
70+
'testing': TestingConfig,
71+
'production': ProductionConfig,
72+
'default': DevelopmentConfig
73+
}

‎day-130/requirements.txt‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
astroid==2.3.3
2+
Click==7.0
3+
Flask==1.1.1
4+
Flask-SQLAlchemy==2.4.1
5+
Flask-WTF==0.14.3
6+
isort==4.3.21
7+
itsdangerous==1.1.0
8+
Jinja2==2.11.1
9+
lazy-object-proxy==1.4.3
10+
MarkupSafe==1.1.1
11+
mccabe==0.6.1
12+
pylint==2.4.4
13+
six==1.14.0
14+
SQLAlchemy==1.3.13
15+
typed-ast==1.4.1
16+
Werkzeug==1.0.0
17+
wrapt==1.11.2
18+
WTForms==2.2.1

‎day-130/run.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from myproject import create_app
2+
import os
3+
4+
env_dist = os.environ
5+
6+
config = env_dist.get('FLASK_APP', 'default')
7+
app = create_app(config)

‎day-130/uwsgi.ini‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[uwsgi]
2+
master = true
3+
http=:5000
4+
chdir = %d
5+
wsgi-file=%drun.py
6+
home=/home/alisx/Project/Article/python100/.venv
7+
callable=app
8+
processes=4
9+
threads=2
10+
buffer-size = 65536
11+
vacuum=true
12+
pidfile =%duwsgi.pid

‎day-130/uwsgi.pid‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
12510

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /