If Defernia has installed, there might be manage_defernia.py command. It helps you to make a configuration, initialize a database, or run a web server.
See also
Script manage_defernia.py
Defernia is a system that supports multiple instances, and instances’ metadata are stored in the configuration file. From here, we assume that our configuration filename is instance.cfg. (Of course, there’s no such file currently.) You can name it freely like dev.cfg or prod.cfg.
You can pass a filename that doesn’t exist into --config option, and the script will confirm would you want to create a such configuration file.
$ manage_defernia.py shell --config instance.cfg
instance.cfg doesn't exist yet; would you create it? [y]
There’s some fields to be set like database URL:
The directory that would contain Mercurial repositories. By default it is a directory named repos located in the current directory.
Repository directory path [/home/dahlia/defernia-env/defernia/repos]:
The database to be used. By default it uses SQLite with a database file (db.sqlite) located in the current directory.
Database URL [sqlite:////home/dahlia/defernia-env/db.sqlite]:
See also
SQLAlchemy — Database Urls
The HMAC secret key. The default key is randomly generated, so skip this if you don’t know about HMAC or secure session.
Secret key for secure cookies [ab03199d87db101aa07fd18e3dc2599a]:
See also
Keys of Facebook application used for login. You can create a new Facebook application from Facebook Developers home.
Facebook App ID: 123456789012345
Facebook App key: 6753a27847d7e4e3518b1837c2f0e716
Facebook App secret key: edd661737bf101806acb51d83e65c5c1
See also
Facebook Developers — Create Application
Key pair of Twitter application used for login. You can create a new Twitter application from Twitter Developers home.
Twitter App key: X0DS1WP71Mhs8NN0r7paRg
Twitter App secret key: AuJyVWiQm9Jvm61koDP0mv3Gsjgf6GDRrNsvqm5qL
See also
See also
Flask — Configuration Handling
What you have to do next is creating tables into your relational database. There are to recommended relational databases:
You make a decision, and then, initialize the database via manage_defernia.py initdb command:
$ manage_defernia.py initdb --config instance.cfg
No news is good news. It doesn’t print anything unless errors happen.
Note
If you would use SQLite, the data file will be automatically created. But if you would use PostgreSQL, the database to be used have to be created first. Create a database via the createdb command PostgreSQL provides:
$ createdb -U postgres -E utf8 -T postgres defernia_db
See also
Command manage_defernia.py initdb
To check whether the installation has sucessful, we can run the unit tests. setup.py test command runs the unit tests.
$ python setup.py test
running test
[100%] 2 of 2 Time: 0:00:00
Failures: 0/2 (6 assertions)
We finished configuring an instance. Now we can run the development web server from command line:
$ manage_defernia.py runserver --config instance.cfg
See also
Command manage_defernia.py runserver
Note
It explains advanced details. If you don’t know about WSGI, skip this section and follow Web server section.
Defernia web application is WSGI-compliant, so it can be served on WSGI servers. For example, in order to serve it on Meinheld server, make a script:
import defernia.web
import meinheld.server
app = defernia.web.create_app(config_filename='instance.cfg')
meinheld.server.listen(('0.0.0.0', 8080))
meinheld.server.run(app)
Let’s cut to the chase. defernia.web.create_app() makes a WSGI application and returns it. It takes a config_filename optionally (and it have to be passed by keyword, not positional). And then, pass the created WSGI application into your favorite WSGI server.