Skip to main content

Utility for load static in AioHttp web framework from Webpack with help of webpack-bundle-tracker JS plugin.

Project description

Utility for load static in AioHttp web framework from Webpack with help of webpack-bundle-tracker JS plugin.

Also this can be used with VueJS.

Usage:

settings.py:

    STATIC_URL = '/static/'
    STATIC_PATH = './static/'
    WEBPACK_MANIFEST_PATH = './frontend/webpack_manifest.json'

main.py:

    from aiohttp import web
    import aiohttp_jinja2
    import jinja2
    from aiohttp_webpack import WebpackManifest
    from settings import *


    @aiohttp_jinja2.template('index.html')
    async def index(request):
        context = {
            'webpack': webpack_manifest.get_links(),
        }

        return context


    if __name__ == '__main__':
        loop = asyncio.get_event_loop()

        app = web.Application()
        aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader('./templates'))

        webpack_manifest = WebpackManifest(WEBPACK_MANIFEST_PATH, STATIC_URL, STATIC_PATH)

        app.add_routes([
            web.get('/', index),
            web.get('/static/{path:.*}', webpack_manifest.handle_static),
        ])

        web.run_app(app)

index.html:

    <html>
      <head>
        <meta charset="utf-8">
        <link rel="stylesheet" href="/static/index.css"> {# here you can use non webpack static too #}
        {{ webpack.css | safe }}
      </head>
      <body>
        <div id="app"></div> {# if you use VueJS #}
        {{ webpack.js | safe }}
      </body>
    </html>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiohttp-webpack-0.0.3.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiohttp_webpack-0.0.3-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file aiohttp-webpack-0.0.3.tar.gz.

File metadata

  • Download URL: aiohttp-webpack-0.0.3.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.7.2

File hashes

Hashes for aiohttp-webpack-0.0.3.tar.gz
Algorithm Hash digest
SHA256 ab96c4a41ee6f2d3d1f206845a8239182a128ca1f18163dc72b22cb3dd05b9e6
MD5 bbd9ea1df4fcb9f5e548565305cbbce0
BLAKE2b-256 92ba23f2603f394b7c464d1183c3049f1dc6807db1212b8395b89a4388390dea

See more details on using hashes here.

File details

Details for the file aiohttp_webpack-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: aiohttp_webpack-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.7.2

File hashes

Hashes for aiohttp_webpack-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0a532bc0730b45b9a027c4a4e8b218cf8bd0c470594e154081c806fd13a7a788
MD5 0a1e0a673d211a425b4b3f348dcca885
BLAKE2b-256 eb1842b7d433af6414ce9e929485ac41a864f5cb4ececc4af67678997d8f3106

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page