views.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:aiohttp-devtools 作者: aio-libs 项目源码 文件源码
def index(request):
    """
    This is the view handler for the "/" url.

    **Note: returning html without a template engine like jinja2 is ugly, no way around that.**

    :param request: the request object see http://aiohttp.readthedocs.io/en/stable/web_reference.html#request
    :return: aiohttp.web.Response object
    """
    # {% if database.is_none and example.is_message_board %}
    # app.router allows us to generate urls based on their names,
    # see http://aiohttp.readthedocs.io/en/stable/web.html#reverse-url-constructing-using-named-resources
    message_url = request.app.router['messages'].url()
    ctx = dict(
        title=request.app['name'],
        styles_css_url=request.app['static_root_url'] + '/styles.css',
        content="""\
  <p>Success! you've setup a basic aiohttp app.</p>
  <p>To demonstrate a little of the functionality of aiohttp this app implements a very simple message board.</p>
  <b>
    <a href="{message_url}">View and add messages</a>
  </b>""".format(message_url=message_url)
    )
    # {% else %}
    ctx = dict(
        title=request.app['name'],
        styles_css_url=request.app['static_root_url'] + '/styles.css',
        content="<p>Success! you've setup a basic aiohttp app.</p>",
    )
    # {% endif %}
    # with the base web.Response type we have to manually set the content type, otherwise text/plain will be used.
    return web.Response(text=BASE_PAGE.format(**ctx), content_type='text/html')
# {% endif %}


# {% if example.is_message_board %}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号