# filename myapp.py
from flask import Flask, url_for
app = Flask(__name__)
@app.route('/')
def index():
return 'hello flask'
@app.route('/test')
def test():
return url_for('index', _external=True)
if __name__ == '__main__':
app.run(debug=True)
(env) F:\tmp>python myapp.py * Running on http://127.0.0.1:5000/ * Restarting with reloader
>>> from myapp import app
>>> with app.app_context():
... print url_for('index', _external=True)
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "F:\tmp\env\lib\site-packages\flask\helpers.py", line 287, in url_for
raise RuntimeError('Application was not able to create a URL '
RuntimeError: Application was not able to create a URL adapter for request indep
endent URL generation. You might be able to fix this by setting the SERVER_NAME
config variable.
>>> app.config['SERVER_NAME'] = 'example.com'
>>> with app.app_context():
... print url_for('index', _external=True)
...
http://example.com/
-------->http://book.muxistudio.com || http://muxistudio.com-------->http://blog.muxistudio.com || -------->http://share.muxistudio.com
127.0.0.1 flask.dev localhost # 域名 127.0.0.1 test.flask.dev localhost # 子域名 127.0.0.1 othertest.flask.dev localhost # 子域名
#... app = Flask(__name__) app.config['SERVER_NAME'] = 'flask.dev:5000' #...
#...
# Blueprint declaration
bp = Blueprint('subdomain', __name__, subdomain="<user>")
#...
# Register the blueprint into the application
app.register_blueprint(bp)
#...
flask.dev:5000 ----> muxistudio.com
server {
listen 80;
listen 443 ssl;
ssl_certificate /usr/local/nginx/ssl/nginx.crt;
ssl_certificate_key /usr/local/nginx/ssl/nginx.key;
server_name ~^www\.(?<user>.+\.)?markdownblog\.com$;
return 301 "$scheme://${user}markdownblog.com$request_uri";
}
server {
listen 80;
listen 443 ssl;
ssl_certificate /usr/local/nginx/ssl/nginx.crt;
ssl_certificate_key /usr/local/nginx/ssl/nginx.key;
server_name ~^.+\.markdownblog\.com$ markdownblog.com;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8085;
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有