Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

License

NotificationsYou must be signed in to change notification settings

molior-dbs/python3-aiohttp-devtools

Repository files navigation

Coveragepypilicense

Dev tools foraiohttp.

aiohttp-devtools provides a number of tools useful when developing applications with aiohttp and associatedlibraries.

Installation

pip install aiohttp-devtools

Usage

Theaiohttp-devtools CLI (and it's shorter aliasadev) consist of two sub-commands:runserver andserve.

runserver

Provides a simple local server for running your application while you're developing.

Usage is simply

adev runserver<app-path>

Note:adev runserver <app-path> will import the whole file, hence it doesn't workwithweb.run_app(app). You can however useif __name__ == '__main__': web.run_app(app).

app-path can be a path to either a directory containing a recognized default file (app.pyormain.py) or to a specific file. The--app-factory option can be used to define which method is calledfrom the app path file, if not supplied some default method names are tried(namely app, app_factory, get_app and create_app, which can bevariables, functions, or coroutines).

Allrunserver arguments can be set via environment variables.

runserver has a few useful features:

  • livereload will reload resources in the browser as your code changes without having to hit refresh, seelivereload for more details.
  • static files are served separately from your main app (generally on8001 while your app is on8000) so you don't have to contaminate your application to serve static files you only need locally.

For more options seeadev runserver --help.

serve

Similar torunserver except just serves static files.

Usage is simply

adev serve<path-to-directory-to-serve>

Likerunserver you get nice live reloading and access logs. For more options seeadev serve --help.

Tutorial

To demonstrate what adev can do when combined with create-aio-app, let's walk through creating a new application:

First let's create a clean python environment to work in and install aiohttp-devtools and create-aio-app.

(it is assumed you've already gotpython,pip andvirtualenv installed)

mkdir my_new_app&&cd my_new_appvirtualenv -p`which python3` env. env/bin/activatepip install aiohttp-devtools create-aio-app

We're now ready to build our new application withcreate-aio-app and we'll name theprojectmy_new_app after the current directory.

We're going to explicitly choose no database here to make this tutorial easier, but you can remove that optionand choose to use a proper database if you like.

You can just hit return to choose the default for all the options.

create-aio-app my_new_app --without-postgres

That's it, your app is now created. You might want to have a look through the local directory's file tree.

Before you can run your app you'll need to install the other requirements, luckily they've already been listed inrequirements/development.txt bycreate-aio-app, to install simply run

pip install -r requirements/development.txt

You can then run your app with just:

adev runserver

With that:

  • your app should be being served atlocalhost:8000 (you can go and play with it in a browser).
  • Your static files are being served atlocalhost:8001, adev has configured your app to know that so it should be rendering properly.
  • any changes to your app's code (.py files) should cause the server to reload, changes to any files(.py as well as.jinja,.js,.css etc.) will cause livereload to prompt your browser to reload the required pages.

That's it, go develop.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors25


[8]ページ先頭

©2009-2025 Movatter.jp