https://www.geeksforgeeks.org/subdomain-in-flask-python/
使用子域名需要首先修改hosts文件
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
127.0.0.1 example.com
127.0.0.1 public.example.com
127.0.0.1 api.example.com
之后再使用
from flask import Flask, render_template, Blueprint
app = Flask(__name__)
website_url = 'example.com:5000'
app.config['SERVER_NAME'] = website_url
public = Blueprint('public', __name__)
api = Blueprint('api', __name__, url_prefix='/api')
@public.route('/helloflask')
def home():
return 'hello flask'
@api.route('/api')
def apihome():
return 'API'
app.register_blueprint(public, subdomain='public')
app.register_blueprint(api, subdomain='api')
@app.route('/')
def index():
#return '<h1>Hello Flask!</h1>'
mkd = '''# header
## header2
[picture](http://www.example.com)
* 1
* 2
* 3
**bold**
'''
return render_template('test_1.html', mkd=mkd)
@app.route('/greet', defaults={'name': 'Programmer'})
@app.route('/greet/<name>')
def greet(name):
return '<h1>Hello, %s!</h1>' % name
0 Comments latest
No comments.