def send_static_files(filename): if not os.path.splitext(filename)[1]: filename += ".html" resp = current_app.send_static_file(filename) resp.mimetype = mimetypes.guess_type(filename)[0] return resp
def show(page): if '.' in page: return current_app.send_static_file(page) if page == 'show' or page.isdigit(): return abort(404) try: return st('modules/pages/%s.html' % page) except TemplateNotFound, e: pass
def get_random_bg_image(): #print os.path.abspath(os.path.dirname(__file__)) #static_dir = os.path.join(os.path.abspath(__file__), 'static') from random import choice static_dir = current_app.static_folder bg_image_dir= 'background_images' random_img_file= choice( os.listdir(static_dir+'/'+bg_image_dir) ) print bg_image_dir+'/'+random_img_file return current_app.send_static_file( bg_image_dir+'/'+random_img_file)
def web_html(file_name): if not file_name: file_name = 'index.html' if file_name != 'favicon.ico': file_name = 'html/' + file_name # 设置csrf_token到cookie中 并会给session同步存储一份 # 读取会从session中读取 csrf_token = generate_csrf() response = make_response(current_app.send_static_file(file_name)) response.set_cookie('csrf_token', csrf_token) return response
def profile_pic(user_id): """ Serve a profile picture. If user picture is not found, return default one. """ fpath = os.path.join(current_app.config['UPLOAD_DIR'], str(user_id) + '.png') if os.path.isfile(fpath): return send_file(fpath) else: return current_app.send_static_file('img/default_profile.png')
def html_file(file_name): if not file_name: file_name = "index.html" if file_name != "favicon.ico": file_name = "html/" + file_name csrf_token = csrf.generate_csrf() response = make_response(current_app.send_static_file(file_name)) response.set_cookie("csrf_token", csrf_token) return response
def send_static(filename): """Sends a file from the static folder if a given file exist. Otherwise, tries additional folders as a fallback. """ try: return current_app.send_static_file(filename) except NotFound: for prefix, folder in locations: if prefix: prefix = '{}{}'.format(prefix, os.sep) if filename.startswith(prefix): filename = filename[len(prefix):] filepath = safe_join(folder, filename) if os.path.isfile(filepath): return send_file(filepath) raise NotFound()
def register(): if request.method == 'POST': username = request.form['username'] password = request.form['password'] email = request.form['email'] if not username or not password or not email: return 'Input not valid.' try: user = User.objects(email=email).get() except Exception: user = User(username=username, password=bcrypt.generate_password_hash(password), email=email) user.save() flask_login.login_user(user) return 'Success.' else: return 'Already exists.' else: return current_app.send_static_file('register.html')
def get_html_file(file_name): """提供html静态文件""" # 根据用户访问的路径提供相应的html文件 if not file_name: # 如果用户访问的是/ file_name = "index.html" if file_name != "favicon.ico": file_name = "html/" + file_name # 生产csrf_token字符串 csrf_token = generate_csrf() # 为用户设置cookie,csrf_token resp = make_response(current_app.send_static_file(file_name)) resp.set_cookie("csrf_token", csrf_token) return resp
def login(): if request.method == 'POST': email = request.form['email'] logging.debug("{} tries to login.".format(email)) try: user = User.objects(email=email).get() if bcrypt.check_password_hash(user.password, request.form['password']): flask_login.login_user(user) logging.debug('Logged in successfully.') flash('Logged in successfully.') return redirect(url_for('index')) else: logging.debug('Wrong password.') flash('Wrong password.') return redirect(url_for('login')) except Exception as e: logging.warning(e) return "User not exist." else: return current_app.send_static_file('login.html')
def ogn_js(): return current_app.send_static_file("ognlive/ogn.js")
def barogram_js(): return current_app.send_static_file("ognlive/barogram.js")
def favicon(): # send_static_file用于返回静态文件 return current_app.send_static_file("news/favicon.ico")
def _static(ds, filename): return current_app.send_static_file(filename=filename)
def show_base_registry_full(): return current_app.send_static_file( 'RegistryStore/registries/en/Base.json' )
def show_odata_service_document(): return current_app.send_static_file('odata')
def res(file_name): return current_app.send_static_file(file_name)
def get_index(): return current_app.send_static_file('./index.html')
def get_web_logo(): return current_app.send_static_file('news/favicon.ico')
def static_root(): return current_app.send_static_file('index.html') return send_from_directory('/', 'index.html')
def hello_world(): return current_app.send_static_file('client.html')
def favicon(): print(current_app.url_map) return current_app.send_static_file("news/favicon.ico")
def favicon(): """查找发送页签图标""" # current_app应用上下文变量,表示当前应用 # send_static_file是flask查找指定静态文件的方法,浏览器自动请求小图标 return current_app.send_static_file('news/favicon.ico')
def hello_world(): return current_app.send_static_file('webchat.html')
def asset(user, asset): # An asset is a binary in someone's garden/<user>/assets directory. # Currently unused. path = '/'.join(["garden", user, 'assets', asset]) return current_app.send_static_file(path)
def home(self): return current_app.send_static_file('index.html')
def index(): return app.send_static_file('index.html')
def show_registries(): return current_app.send_static_file('Registries.json')
def getReport(fn): return current_app.send_static_file("pdf/" + fn)
def favicon() -> Response: return current_app.send_static_file("images/favicon.ico")
def get_favicon(): """Serve favicon""" return current_app.send_static_file('favicon.ico')
def serve_static(*args, **kwargs): return current_app.send_static_file(*args, **kwargs)
def get_fav(): return current_app.send_static_file('ico/favicon.ico')
def horizZoomControl_js(): return current_app.send_static_file("ognlive/horizZoomControl.js")
def crossdomain(): return current_app.send_static_file('crossdomain.xml')
def util_js(): return current_app.send_static_file("ognlive/util.js")
def serveIndex(): print("hi") return current_app.send_static_file("index.html")
def index(): return current_app.send_static_file('webchat.html')
def serveStatics(path): return current_app.send_static_file(path)
def index(): #return "Hello world!" #return render_template("test.html") return current_app.send_static_file("maltools.html")
def favicon(): """title左侧图标""" # return 'Users/zhangjie/Desktop/Information_29/info/static/news/favicon.ico' return current_app.send_static_file('news/favicon.ico')
def get_terms_kt(): print "abc" return current_app.send_static_file('terms/ktclub.txt')
def favicon(): return current_app.send_static_file("news/favicon.ico")
def dashboard(): return current_app.send_static_file('index.html')
def hello(): return app.send_static_file('index.html')
def get(self): """ HTTP GET request :return: index html page """ return current_app.send_static_file('index.html')
def static_file(path): return app.send_static_file(path)
def show_redfish_metadata_document(): g.metadata = True return current_app.send_static_file('$metadata')
def favicon(): # 我的思路是写一个重定向, 最简单; 或者,使用模板渲染也比较简单. # return redirect("/static/favicon.ico") # 官方思路: send_static_file 是专门用于返回 静态资源 的函数 return current_app.send_static_file("favicon.ico")
def show_base_registry(): return current_app.send_static_file('Registries/Base.json')
def index(): return current_app.send_static_file('index.html')
def show_redfishserver_registry_full(): return current_app.send_static_file( 'RegistryStore/registries/en/BluebirdServer.json' )
def get_fav(): print(__name__) return current_app.send_static_file('img/favicon.ico')
def pict(filename): return current_app.send_static_file("ognlive/pict/" + filename)
def robots_txt(): """Serves the robots.txt file to manage the indexing of the site by search enginges""" return current_app.send_static_file('robots.txt')
def favicon_gif(): return current_app.send_static_file("ognlive/pict/favicon.gif")
def embed_js(): return current_app.send_static_file('embed.js')
def web_logo(): return current_app.send_static_file("news/favicon.ico")