Configuration¶
A configuration example is provided in pytition/settings/config_example.py. You should copy and edit it to configure Pytition.
Mandatory settings¶
You must set the following variables:
-
ALLOWED_HOSTS
= ['127.0.0.1', 'localhost', '[::1]']¶ - Enter the hostname(s) (aka VirtualHost(s)) Django should accept.For instance mydomain.tld or petition.mydomain.tld
See also
Details on how to set this up are available in Django documentation:
ALLOWED_HOSTS
Example:
ALLOWED_HOSTS = ['www.mysuperpetition.org', 'mysuperpetition.org']
-
DATABASES
= {}¶ - Enter a database setting.This will tell Django what database engine you want to use (supported ones are listed there: https://docs.djangoproject.com/en/2.2/ref/settings/#std:setting-DATABASE-ENGINE)It will also give parameters like user/password credentials, server host/port etc.
See also
Details on how to set this up are available in Django documentation: https://docs.djangoproject.com/en/2.2/ref/settings/#std:setting-DATABASES
In the following example, credentials are in my.cnf file:
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'OPTIONS': { 'read_default_file': '/home/pytition/my.cnf', 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'", }, } }
-
MEDIA_ROOT
= ''¶ - Enter the file system path to the directory that will be used to serve user uploaded files.This must be an initially empty directory.You must also configure a web server (apache, nginx or other) to servethe content of this directory according to your MEDIA_URL settingwhich default is
'/mediaroot/'
in the example config.For instance you can have this kind of setting:
MEDIA_ROOT = '/home/pytition/www/mediaroot' MEDIA_URL = '/mediaroot/'
And then in your apache config:
Alias /mediaroot /home/pytition/www/mediaroot
Or in your nginx config:
location /mediaroot { alias /home/pytition/www/mediaroot; }
See also
https://docs.djangoproject.com/en/2.2/ref/settings/#std:setting-MEDIA_ROOT for more details from Django Documentation
-
MEDIA_URL
= '/mediaroot/'¶ - enter the prefix that will be used for the url to refer to uploaded files.it must end with a forward slash ‘/’.you must also configure a web server (apache, nginx or other) to servethe content of the directory configured as MEDIA_ROOT according to this settingit defaults to
'/mediaroot/'
in the example config.for instance you can have this kind of setting:
MEDIA_ROOT = '/home/pytition/www/mediaroot' MEDIA_URL = '/mediaroot/'
and then in your apache config:
alias /mediaroot /home/pytition/www/mediaroot
or in your nginx config:
location /mediaroot { alias /home/pytition/www/mediaroot; }
See also
https://docs.djangoproject.com/en/2.2/ref/settings/#std:setting-MEDIA_URL for more details from django documentation
-
SECRET_KEY
= ''¶ - Enter a random, unique and private secret key.Pytition won’t start without it.Never share it, don’t commit in git.See https://docs.djangoproject.com/en/2.2/ref/settings/#std:setting-SECRET_KEY for more details from Django documentationTo generate it, you can use the following command from your virtualenv with Django installed:
$ python3 -c "from django.core.management.utils import get_random_secret_key as g; print(g())"
Example:
SECRET_KEY = 'my secret key here'
-
STATIC_ROOT
= None¶ - Enter the file system path to the directory that will be used to serve your static files.This must be an initially empty directory.You must also configure a web server (apache, nginx or other) to servethe content of this directory according to your STATIC_URL settingwhich default is
'/static/'
in the example config.For instance you can have this kind of setting:
STATIC_ROOT = '/home/pytition/www/static' STATIC_URL = '/static/'
And then in your apache config:
Alias /static /home/pytition/www/static
Or in your nginx config:
location /static { alias /home/pytition/www/static; }
See also
https://docs.djangoproject.com/en/2.2/ref/settings/#std:setting-STATIC_ROOT for more details from Django Documentation
-
STATIC_URL
= '/static/'¶ - enter the prefix that will be used for the url to refer to static files.it must end with a forward slash ‘/’.you must also configure a web server (apache, nginx or other) to servethe content of the directory configured as STATIC_ROOT according to this settingit defaults to
'/static/'
in the example config.for instance you can have this kind of setting:
STATIC_ROOT = '/home/pytition/www/static' STATIC_URL = '/static/'
and then in your apache config:
alias /static /home/pytition/www/static
or in your nginx config:
location /static { alias /home/pytition/www/static; }
See also
https://docs.djangoproject.com/en/2.2/ref/settings/#std:setting-static_url for more details from django documentation
Warning
The TINYMCE_JS_URL
setting must be present in your config file if you modified the STATIC_URL
setting from its default value (/static/
), either before of after the DO NOT EDIT AFTER THIS BANNER
. It is already present in the config_example.py file.
Not mandatory but important settings¶
You are highly encouraged to set the following variables in a production environment:
Pytition specific settings¶
-
USE_MAIL_QUEUE
= False¶ - Set it to
True
if you want email sending to retry upon failure.Email transmition naturally have retries if the first SMTP server accepts itIf your SMTP server refuses to handle the email (anti-flood throttle?) then itis up to you to retry, and this is what the mail queue does for you.This is especially needed if you don’t own the first-hop SMTP serverand cannot configure it to always accept your emails regardless of the sendingfrequency.It is HIGHLY recommended to set this toTrue
.If you chose to use the mail queue, you must also eitherset a cron job (automatic task execution), or
serve the Django app through uwsgi (recommended setup)
Warning
The first time you switch this setting from
False
toTrue
, you must run theDJANGO_SETTINGS_MODULE=pytition.settings.config python3 pytition/manage.py migrate
command again. Beware to run it while being in your virtualenv.
-
ALLOW_REGISTER
= True¶ - Whether you want to allow anyone to create an account and host petitionson your Pytition instance.Set it to
False
for a private instance.Set it toTrue
for a public instance.
-
DEFAULT_NOREPLY_MAIL
= 'noreply@domain.tld'¶ - Default address for ‘Reply to’ field in mail sent on account creation
Django settings¶
The following settings are important to set so that the email sent by Pytition are less likely to be considered as spam/junk. You should configure a real SMTP email account and not just rely on “fake” email address from local sendmail:
|
Other optional settings¶
Those are things you can configure to customize your Pytition instance:
-
SITE_NAME
= 'Pytition'¶ - The name of your Pytition instance.
-
FOOTER_TEMPLATE
= None¶ - Leave it set to None for no footer.This should contain the relative path to your footer template.That would be the location for any “legal mention” / “GDPR” / “TOS” link.
Example:
FOOTER_TEMPLATE = 'layouts/footer.html.example'
-
DISABLE_USER_PETITION
= False¶ - If set to True, users won’t be able to create petitions in their name, but only for an organization
-
RESTRICT_ORG_CREATION
= False¶ - If set to True, regular users won’t be able to create new organizations.Only superusers will be allowed to