Flask Snippets

Snippets are unofficial and unmaintained.

This is an archived view of user-submitted snippets. Despite being hosted on the Flask site, they are not official. No Flask maintainer has curated or checked the snippets for security, correctness, or design.

Preconfigured interactive shell

Posted by Dag Odenhall on 2010-05-28 @ 07:00 and filed in Utilities

The documentation recommends putting imports in a module and import that when you're in an interactive session. Even better, I think, is to make an executable that launches a preconfigured Python shell.

Put something like this in for example shell.py and run chmod +x shell.py.

#!/usr/bin/env python

import os
import readline
from pprint import pprint

from flask import *

from myapp import *
from utils import *
from db import *
from models import *


os.environ['PYTHONINSPECT'] = 'True'

Normally import * should be avoided but unless you get namespace collisions it makes sense for an interactive shell environment.

Now you can simply do ./shell.py.

This snippet by Dag Odenhall can be used freely for anything you like. Consider it public domain.

Comments