Starting a project based on playdoh¶
The secret to what makes playdoh fun is the funfactory module. When you install funfactory from PyPI or from source you get a command line script that you can use to start a new playdoh project. Install funfactory with a package manager like pip:
pip install funfactory
You’ll now have the Playdoh installer script. Read through funfactory --help or start a new project like this:
funfactory --python=python2.6 --pkg=yourapp
The automatic install process goes like this:
- Clone the Playdoh git repository
- Create a custom yourapp package
- Create a virtualenv named yourapp (if not already in a virtualenv)
- Install/compile all requirements
- Create a local settings file in yourapp/settings/local.py and fill in some settings.
If a virtualenv needs to be created and you have virtualenvwrapper installed, the created virtualenv will go in your WORKON_HOME directory. Otherwise the virtualenv will be installed in .virtualenv.
The Playdoh project layout uses a vendor library, i.e. a subdirectory vendor that contains all pure Python libraries required. In addition, a few C based libraries (such as MySQL-python, bcrypt, etc) get built by the installer. For more information on vendor libraries, read pip and friends: Packaging.
By default the funfactory installer configures your app to use a MySQL database named playdoh_app. You’ll need to create the database manually:
mysql -u root -e 'create database playdoh_app;'
If you need to adjust any settings for the database connection, edit yourproject/settings/local.py. Synchronize tables and initial data:
Start the development server:
./manage.py runserver 0.0.0.0:8000
You can now view the dev server at http://localhost:8000/ – hooray!
If you start adding pieces that should go back into playdoh, you will probably want to patch funfactory, which is the core of Playdoh.
If your app’s configuration requires you to add or remove apps, middleware, or template context processors from the default funfactory configuration, you can use the get_apps, get_middleware, and get_context_processors functions. See the settings management API documentation.
Installing a project by hand¶
The installer script automates everything you’d need to do by hand but it’s simple to do it yourself. Here’s what you would do:
- Clone the Playdoh git repository into customproject.
- cd into that directory and rename project to customproject (this is the actual Python module).
- Edit setup.py so the module name is customproject
- Copy customproject/settings/local.py-dist to customproject/settings/local.py.
- Edit local.py:
- Fill in your DB credentials
- Enter a secret key
- Enter an HMAC key for bcrypt password hashing
- Create a virtualenv (if not already in one)
- Run pip install -r requirements/compiled.txt
Then you should be ready to run syncdb and start up the server:
./manage.py syncdb ./manage.py runserver 0.0.0.0:8000