mag.py is Magpy’s command-line utility for administrative tasks. This document outlines what it can do.
mag.py <command> [options]
command should be one of the commands listed in this document. options, which is optional, should be zero or more of the options available for the given command.
Run mag.py help to display usage information and a list of the commands provided by each application.
Run mag.py help --commands to display a list of all available commands.
Run mag.py help <command> to display a description of the given command and a list of its available options.
Run mag.py version to display the current Mag.py version.
Creates a Magpy app directory structure for the given app name in the current directory or the given destination.
By default the directory created contains a models.py file and other app template files. If only the app name is given, the app directory will be created in the current working directory.
If the optional destination is provided, Magpy will use that existing directory rather than creating a new one. You can use ‘.’ to denote the current working directory.
The new app is not automically brought into use, see add_app below.
For example:
mag.py startapp myapp /Users/jezdez/Code/myapp
Adds the app (or apps) to the installed apps setting. This is required for the Magpy Server to recognise your application.
Note your application needs to also be in the Python path, i.e. use the setup.py file of the application to install it into your packages directory.
Add a setting to the database. Settings are any little bits of site specific information that you do not want to hard code into your application.
Settings have a category, a setting name (i.e. key) and value.
Show all URLs from the installed applications. Very useful for debugging.
Load the models from app_name(s).
Add a pickle file of instances to the database.
Make a cookie secret file.
Remove an app_name(s) from installed apps.
Remove a setting from the given setting category.
Run the REST server. See Serverside Application Server
Runs tests for the given application.
Collects the static files into the static root.
Define the static root with:
mag.py add_setting static root <filepath>
Each installed app (i.e. one that has been enabled with add_app), has a static directory.
The default is to take these files and group them by application. So an app with example/static/js/example.js will become static/example/js/example.js. To prevent this behaviour, use -p
The mag.py commands will use pretty color-coded output if your terminal supports ANSI-colored output. It won’t use the color codes if you’re piping the command’s output to another program.
The colors used for syntax highlighting can be customized. Django ships with three color palettes:
You select a palette by setting a DJANGO_COLORS environment variable to specify the palette you want to use. For example, to specify the light palette under a Unix or OS/X BASH shell, you would run the following at a command prompt:
export DJANGO_COLORS="light"
You can also customize the colors that are used. Magpy specifies a number of roles in which color is used:
Each of these roles can be assigned a specific foreground and background color, from the following list:
Each of these colors can then be modified by using the following display options:
A color specification follows one of the following patterns:
where role is the name of a valid color role, fg is the foreground color, bg is the background color and each option is one of the color modifying options. Multiple color specifications are then separated by semicolon. For example:
export DJANGO_COLORS="error=yellow/blue,blink;notice=magenta"
would specify that errors be displayed using blinking yellow on blue, and notices displayed using magenta. All other color roles would be left uncolored.
Colors can also be specified by extending a base palette. If you put a palette name in a color specification, all the colors implied by that palette will be loaded. So:
export DJANGO_COLORS="light;error=yellow/blue,blink;notice=magenta"
would specify the use of all the colors in the light color palette, except for the colors for errors and notices which would be overridden as specified.
If you use the Bash shell, consider installing the Django bash completion script, which lives in extras/django_bash_completion in the Django distribution. It enables tab-completion of mag.py commands, so you can, for instance...
Applications can make commands available, see Custom Commands for more details.