当前位置: 首页>>代码示例>>Python>>正文


Python Sanic.static方法代码示例

本文整理汇总了Python中sanic.Sanic.static方法的典型用法代码示例。如果您正苦于以下问题:Python Sanic.static方法的具体用法?Python Sanic.static怎么用?Python Sanic.static使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sanic.Sanic的用法示例。


在下文中一共展示了Sanic.static方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: app

# 需要导入模块: from sanic import Sanic [as 别名]
# 或者: from sanic.Sanic import static [as 别名]
 def app(self):
     app = Sanic(__name__)
     self.jinja = SanicJinja2(
         app,
         loader=FileSystemLoader([
             str(app_root / 'datasette' / 'templates')
         ]),
         autoescape=True,
     )
     self.jinja.add_env('escape_css_string', escape_css_string, 'filters')
     self.jinja.add_env('quote_plus', lambda u: urllib.parse.quote_plus(u), 'filters')
     self.jinja.add_env('escape_table_name', escape_sqlite_table_name, 'filters')
     app.add_route(IndexView.as_view(self), '/<as_json:(.jsono?)?$>')
     # TODO: /favicon.ico and /-/static/ deserve far-future cache expires
     app.add_route(favicon, '/favicon.ico')
     app.static('/-/static/', str(app_root / 'datasette' / 'static'))
     app.add_route(
         DatabaseView.as_view(self),
         '/<db_name:[^/\.]+?><as_json:(.jsono?)?$>'
     )
     app.add_route(
         DatabaseDownload.as_view(self),
         '/<db_name:[^/]+?><as_db:(\.db)$>'
     )
     app.add_route(
         TableView.as_view(self),
         '/<db_name:[^/]+>/<table:[^/]+?><as_json:(.jsono?)?$>'
     )
     app.add_route(
         RowView.as_view(self),
         '/<db_name:[^/]+>/<table:[^/]+?>/<pk_path:[^/]+?><as_json:(.jsono?)?$>'
     )
     return app
开发者ID:terranodo,项目名称:datasette,代码行数:35,代码来源:app.py

示例2: test_static_file

# 需要导入模块: from sanic import Sanic [as 别名]
# 或者: from sanic.Sanic import static [as 别名]
def test_static_file(static_file_directory, file_name):
    app = Sanic('test_static')
    app.static(
        '/testing.file', get_file_path(static_file_directory, file_name))

    request, response = app.test_client.get('/testing.file')
    assert response.status == 200
    assert response.body == get_file_content(static_file_directory, file_name)
开发者ID:penelopeia,项目名称:sanic,代码行数:10,代码来源:test_static.py

示例3: test_static_directory

# 需要导入模块: from sanic import Sanic [as 别名]
# 或者: from sanic.Sanic import static [as 别名]
def test_static_directory(file_name, base_uri, static_file_directory):

    app = Sanic('test_static')
    app.static(base_uri, static_file_directory)

    request, response = app.test_client.get(
        uri='{}/{}'.format(base_uri, file_name))
    assert response.status == 200
    assert response.body == get_file_content(static_file_directory, file_name)
开发者ID:penelopeia,项目名称:sanic,代码行数:11,代码来源:test_static.py

示例4: test_static_head_request

# 需要导入模块: from sanic import Sanic [as 别名]
# 或者: from sanic.Sanic import static [as 别名]
def test_static_head_request(file_name, static_file_directory):
    app = Sanic('test_static')
    app.static(
        '/testing.file', get_file_path(static_file_directory, file_name),
        use_content_range=True)

    request, response = app.test_client.head('/testing.file')
    assert response.status == 200
    assert 'Accept-Ranges' in response.headers
    assert 'Content-Length' in response.headers
    assert int(response.headers[
               'Content-Length']) == len(
                   get_file_content(static_file_directory, file_name))
开发者ID:penelopeia,项目名称:sanic,代码行数:15,代码来源:test_static.py

示例5: test_static_content_range_empty

# 需要导入模块: from sanic import Sanic [as 别名]
# 或者: from sanic.Sanic import static [as 别名]
def test_static_content_range_empty(file_name, static_file_directory):
    app = Sanic('test_static')
    app.static(
        '/testing.file', get_file_path(static_file_directory, file_name),
        use_content_range=True)

    request, response = app.test_client.get('/testing.file')
    assert response.status == 200
    assert 'Content-Length' in response.headers
    assert 'Content-Range' not in response.headers
    assert int(response.headers[
               'Content-Length']) == len(get_file_content(static_file_directory, file_name))
    assert response.body == bytes(
        get_file_content(static_file_directory, file_name))
开发者ID:penelopeia,项目名称:sanic,代码行数:16,代码来源:test_static.py

示例6: test_static_content_range_error

# 需要导入模块: from sanic import Sanic [as 别名]
# 或者: from sanic.Sanic import static [as 别名]
def test_static_content_range_error(file_name, static_file_directory):
    app = Sanic('test_static')
    app.static(
        '/testing.file', get_file_path(static_file_directory, file_name),
        use_content_range=True)

    headers = {
        'Range': 'bytes=1-0'
    }
    request, response = app.test_client.get('/testing.file', headers=headers)
    assert response.status == 416
    assert 'Content-Length' in response.headers
    assert 'Content-Range' in response.headers
    assert response.headers['Content-Range'] == "bytes */%s" % (
        len(get_file_content(static_file_directory, file_name)),)
开发者ID:penelopeia,项目名称:sanic,代码行数:17,代码来源:test_static.py

示例7: test_static_content_range_front

# 需要导入模块: from sanic import Sanic [as 别名]
# 或者: from sanic.Sanic import static [as 别名]
def test_static_content_range_front(file_name, static_file_directory):
    app = Sanic('test_static')
    app.static(
        '/testing.file', get_file_path(static_file_directory, file_name),
        use_content_range=True)

    headers = {
        'Range': 'bytes=12-'
    }
    request, response = app.test_client.get('/testing.file', headers=headers)
    assert response.status == 200
    assert 'Content-Length' in response.headers
    assert 'Content-Range' in response.headers
    static_content = bytes(get_file_content(
        static_file_directory, file_name))[12:]
    assert int(response.headers[
               'Content-Length']) == len(static_content)
    assert response.body == static_content
开发者ID:penelopeia,项目名称:sanic,代码行数:20,代码来源:test_static.py

示例8: Sanic

# 需要导入模块: from sanic import Sanic [as 别名]
# 或者: from sanic.Sanic import static [as 别名]
import os
import ujson
from backend.api import api
from backend.config import Config
from backend.helper import authenticate
from backend.worker import TokenCleaner
from sanic import Sanic
from sanic.request import Request
from sanic.response import html, redirect


app = Sanic('react_sanic')
app.blueprint(api)
build_dir = os.path.join(os.path.dirname(__file__), 'frontend', 'build')
app.static('/build', build_dir, name='build')


# noinspection PyUnusedLocal
def home(request: Request) -> html:
    html_content = open(os.path.join(build_dir, 'index.html'), 'r').read()
    return html(html_content)


@app.middleware('request')
async def before_request(request: Request):
    if request.path.startswith('/build') or request.path in ['/api/login', '/api/register', '/api/is_authenticated']:
        return None
    token, user_id = authenticate(request)
    if request.path in ['/', '/login', '/register']:
        if user_id and request.path == '/login':
            return redirect('/home')
开发者ID:tarikbauer,项目名称:react_sanic,代码行数:33,代码来源:run.py

示例9: Environment

# 需要导入模块: from sanic import Sanic [as 别名]
# 或者: from sanic.Sanic import static [as 别名]
from time import time

from sanic import Sanic
from sanic.response import html, json
from jinja2 import Environment, PackageLoader, Markup
from asyncpg import create_pool

from monocle import sanitized as conf
from monocle.bounds import center
from monocle.names import DAMAGE, MOVES, POKEMON
from monocle.web_utils import get_scan_coords, get_worker_markers, Workers, get_args


env = Environment(loader=PackageLoader('monocle', 'templates'))
app = Sanic(__name__)
app.static('/static', resource_filename('monocle', 'static'))


def social_links():
    social_links = ''

    if conf.FB_PAGE_ID:
        social_links = '<a class="map_btn facebook-icon" target="_blank" href="https://www.facebook.com/' + conf.FB_PAGE_ID + '"></a>'
    if conf.TWITTER_SCREEN_NAME:
        social_links += '<a class="map_btn twitter-icon" target="_blank" href="https://www.twitter.com/' + conf.TWITTER_SCREEN_NAME + '"></a>'
    if conf.DISCORD_INVITE_ID:
        social_links += '<a class="map_btn discord-icon" target="_blank" href="https://discord.gg/' + conf.DISCORD_INVITE_ID + '"></a>'
    if conf.TELEGRAM_USERNAME:
        social_links += '<a class="map_btn telegram-icon" target="_blank" href="https://www.telegram.me/' + conf.TELEGRAM_USERNAME + '"></a>'

    return Markup(social_links)
开发者ID:UnownFinder,项目名称:Monocle,代码行数:33,代码来源:web_sanic.py

示例10: getuserkey

# 需要导入模块: from sanic import Sanic [as 别名]
# 或者: from sanic.Sanic import static [as 别名]
def getuserkey(uid):
    return 'user:{}'.format(uid)


def getsessionkey(sid):
    return 'session:{}'.format(sid)


async def getitems(indexes):
    return await store.hgetall([getitemkey(index) for index in indexes])


async def getitem(index):
    return await store.hgetall(getitemkey(index))


async def getitembyslug(slug):
    index = await store.hget('items:slugs', slug)
    return await getitem(index) if index is not None else None


def getitemkey(index):
    return 'item:{}'.format(index)


app.static('/', './static')

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8000, debug=True)
开发者ID:mohd-akram,项目名称:item.tf,代码行数:31,代码来源:main.py

示例11: Sanic

# 需要导入模块: from sanic import Sanic [as 别名]
# 或者: from sanic.Sanic import static [as 别名]
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from sanic import Sanic
from sanic.response import html
from jinja2 import Environment, PackageLoader, select_autoescape

# sys.path.append(os.path.dirname(os.getcwd()))
# sys.path.append(os.getcwd())

APP_NAME = 'budshome.com'
HOST = ['localhost:5555', '0.0.0.0:5555']
TIMEZONE = 'Asia/Chengdu'

BH = Sanic(APP_NAME)
BH.static('/static', './static')
# session_interface = InMemorySessionInterface()

# jinjia2 start
env = Environment(
    loader = PackageLoader('budshome', '../templates'),
    autoescape = select_autoescape(['html', 'xml', 'json'])
)

def page(tpl, **kwargs):
    template = env.get_template(tpl)
    return html(template.render(kwargs))
# jinjia2 end

# mongodb start
MONGODB = dict(
开发者ID:Ouds,项目名称:Ouds-cms,代码行数:33,代码来源:basis.py

示例12: Sanic

# 需要导入模块: from sanic import Sanic [as 别名]
# 或者: from sanic.Sanic import static [as 别名]
from sanic import Sanic
from sanic.response import json

app = Sanic(__name__)

# Static file serving
#
# TODO: static file serving need to be used only in debug mode.
# See https://github.com/libreirc/libreirc/issues/8 for the further details.
app.static('/', './public/index.html')
app.static('*', './public')

app.run(host="0.0.0.0", port=4321)
开发者ID:openirc,项目名称:openirc,代码行数:15,代码来源:main.py

示例13: Sanic

# 需要导入模块: from sanic import Sanic [as 别名]
# 或者: from sanic.Sanic import static [as 别名]
import os
import pathlib

import aiomysql
import jinja2
import jinja2_sanic

from sanic import Sanic
from sanic.response import HTTPResponse, redirect


static_folder = pathlib.Path(__file__).resolve().parent / 'public' / 'css'

app = Sanic(__name__)
app.static('/css', str(static_folder))

jinja2_sanic.setup(app, loader=jinja2.FileSystemLoader('./templates', encoding='utf8'))


app.secret_key = os.environ.get('ISHOCON2_SESSION_SECRET', 'showwin_happy')

_config = {
    'db_host': os.environ.get('ISHOCON2_DB_HOST', 'localhost'),
    'db_port': int(os.environ.get('ISHOCON2_DB_PORT', '3306')),
    'db_username': os.environ.get('ISHOCON2_DB_USER', 'ishocon'),
    'db_password': os.environ.get('ISHOCON2_DB_PASSWORD', 'ishocon'),
    'db_database': os.environ.get('ISHOCON2_DB_NAME', 'ishocon2'),
}


def render_template(template_name, request, **kwargs):
开发者ID:showwin,项目名称:ISHOCON2,代码行数:33,代码来源:app.py

示例14: Sanic

# 需要导入模块: from sanic import Sanic [as 别名]
# 或者: from sanic.Sanic import static [as 别名]
MESSAGE_SIZE = 10 * (2 ** 10) ** 2
TILE_SIZE = [256, 256]


warnings.simplefilter('ignore', Image.DecompressionBombWarning)
Image.MAX_IMAGE_PIXELS = None


Config.WEBSOCKET_MAX_SIZE = 200 * (2 ** 10) ** 2

sanic.handlers.INTERNAL_SERVER_ERROR_HTML = '''
Something went wrong! :(
'''

APP = Sanic()
APP.static('', '../client/dist')
APP.static('', '../client/dist/index.html')


class ClientError(RuntimeError):
    pass


class Result(Exception):
    def __init__(self, result):
        super().__init__()
        self.result = result


class Message(object):
    # pylint: disable=missing-docstring
开发者ID:SpatialTranscriptomicsResearch,项目名称:st_aligner,代码行数:33,代码来源:app.py

示例15: Sanic

# 需要导入模块: from sanic import Sanic [as 别名]
# 或者: from sanic.Sanic import static [as 别名]
from sanic import Sanic
from sanic.response import json, html
import os
from get_quake_data import get_quake_data
import settings

app = Sanic(__name__)
app.static('/static', settings.STATIC_DIR)


@app.route("/")
async def test(request):
    template = open(os.getcwd() + "/project/index.html")
    return html(template.read())

@app.route("/json")
async def test(request):
    return json(get_quake_data())


app.run(host="127.0.0.1", port=8000, debug=True)
开发者ID:jmcclena94,项目名称:seaquake,代码行数:23,代码来源:main.py


注:本文中的sanic.Sanic.static方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。