Developing Pecan Applications Locally

Reloading Automatically as Files Change

Pausing to restart your development server as you work can be interruptive, so pecan serve provides a --reload flag to make life easier.

To provide this functionality, Pecan makes use of the Python watchdog library. You’ll need to install it for development use before continuing:

$ pip install watchdog
Downloading/unpacking watchdog
...
Successfully installed watchdog
$ pecan serve --reload config.py
Monitoring for changes...
Starting server in PID 000.
serving on 0.0.0.0:8080, view at http://127.0.0.1:8080

As you work, Pecan will listen for any file or directory modification events in your project and silently restart your server process in the background.

Debugging Pecan Applications

Pecan comes with simple debugging middleware for helping diagnose problems in your applications. To enable the debugging middleware, simply set the debug flag to True in your configuration file:

app = {
    ...
    'debug': True,
    ...
}

Once enabled, the middleware will automatically catch exceptions raised by your application and display the Python stack trace and WSGI environment in your browser when runtime exceptions are raised.

To improve debugging, including support for an interactive browser-based console, Pecan makes use of the Python backlash <https://pypi.python.org/pypi/backlash> library. You’ll need to install it for development use before continuing:

$ pip install backlash
Downloading/unpacking backlash
...
Successfully installed backlash

Serving Static Files

Pecan comes with simple file serving middleware for serving CSS, Javascript, images, and other static files. You can configure it by ensuring that the following options are specified in your configuration file:

app = {
    ...
    'debug': True,
    'static_root': '%(confdir)/public
}

where static_root is an absolute pathname to the directory in which your static files live. For convenience, the path may include the %(confdir) variable, which Pecan will substitute with the absolute path of your configuration file at runtime.

Note

In production, app.debug should never be set to True, so you’ll need to serve your static files via your production web server.