Skip to content

Installation

Alvin Tang edited this page Sep 26, 2021 · 9 revisions

Settings

The default Django settings module for this application is hacktheback.settings. You shouldn't modify this module directly. Instead, it is recommended that you configure your application through environment variables.

Environment Variables

The project uses Django-environ to load environment variables and cast them accordingly to update settings. Learn how to format environment variables of varying types in the Django-environ docs.

  • SITE_NAME (default: "Hack the Back")
    • Description: The desired title of your application. This will be used in the email template context.
    • Type: str
  • DEBUG (default: True)
    • Description (from Django docs): A boolean that turns on/off debug mode.
    • Type: bool
    • Warning: Never deploy a site into production with DEBUG turned on.
  • DEBUG_AS_PRODUCTION (default: False)
    • Description: If DEBUG=True, then this environment variable should be considered. A boolean that turns on/off debug mode as if were a production environment. If this is turned off, then sqlite3 is used as the database and emails are sent to standard output.
    • Type: bool
  • SECRET_KEY
    • Description (from Django docs): A secret key for a particular Django installation. This is used to provide cryptographic signing, and should be set to a unique, unpredictable value.
    • Type: str
    • Warning: Keep the secret key used in production a secret!
  • ALLOWED_HOSTS (default: ["localhost", "127.0.0.1"])
    • Description (from Django docs): A list of strings representing the host/domain names that this Django site can serve. This is a security measure to prevent HTTP Host header attacks, which are possible even under many seemingly-safe web server configurations.
    • Type: list (FOO=a,b,c)
  • DATABASE_URL
    • Description: The URL of the database server. It is recommended that you use a PostgreSQL database that has a URL starting with postgres://, pgsql://, psql:// or postgresql://.
    • Type: str
    • Required when (DEBUG=True and DEBUG_AS_PRODUCTION=True) or DEBUG=False
    • Warning: In order to use unsafe characters you have to encode with urllib.parse.encode before you set it into the environment.
  • EMAIL_URL
    • Description: The URL of the SMTP server.
    • Type: str
    • Required when (DEBUG=True and DEBUG_AS_PRODUCTION=True) or DEBUG=False
    • Warning: In order to use unsafe characters you have to encode with urllib.parse.encode before you set it into the environment.
  • STATIC_URL (default: /static/)
    • Description (from Django docs): URL to use when referring to static files located in STATIC_ROOT.
    • Type: str
    • Warning: In order to use unsafe characters you have to encode with urllib.parse.encode before you set it into the environment.
  • MEDIA_MAX_FILE_SIZE (default: 52428800)
    • Description: The maximum file size that can be uploaded by any user. The default is 50MB.
    • Type: int
  • MEDIA_URL (default: /media/)
    • Description (from Django docs): URL that handles the media served from MEDIA_ROOT, used for managing stored files.
    • Type: str
    • Warning: In order to use unsafe characters you have to encode with urllib.parse.encode before you set it into the environment.
  • ADMINS (default: [])
  • CORS_ALLOWED_ORIGINS (default: ["http://localhost:8000", "http://localhost:3000", "http://localhost:4200"])
    • Description (from django-cors-headers README.md): A list of origins that are authorized to make cross-site HTTP requests.
    • Type: list (FOO=a,b,c)
    • Warning: In order to use unsafe characters you have to encode with urllib.parse.encode before you set it into the environment.
  • MJML_API_URL (default: https://api.mjml.io/v1/render)
    • Description: The API URL to render MJML into HTML.
    • Type: str
  • MJML_APPLICATION_ID
    • Description: The application id to access the MJML API. It can be obtained by signing up for the MJML REST API.
    • Type: str
  • MJML_SECRET_KEY
    • Description: The secret key to access the MJML API. It can be obtained by signing up for the MJML REST API.
    • Type: str

JWT Settings

  • JWT_EXPIRATION (default: 60 * 5 or 5 minutes)
    • Description: The number of seconds between the time a JWT is issued (for auth) and when it expires.
    • Type: int
  • JWT_REFRESH_EXPIRATION (default: 60 * 60 * 24 * 7 or 7 days)
    • Description: The number of seconds between the time a JWT is first issued (for auth) and when a JWT can no longer be refreshed.
    • Type: int
  • JWT_AUTH_HEADER_PREFIX (default: JWT)
    • Description: Authorization header prefix.
    • Type: str

Account Activation, Registration and Password Reset Settings

  • SEND_ACTIVATION_EMAIL (default: True)
    • Description: If turned on, a user will be required to click the activation link sent in email after creating an account or updating their email.
    • Type: bool
  • ACTIVATION_URL (default: activate?uid={uid}&token={token})
    • Description: The URL to your frontend activation page. It should contain {uid} and {token} placeholders. You should pass uid and token to the activation REST endpoint or mutation.
    • Type: str
    • Warning: In order to use unsafe characters you have to encode with urllib.parse.encode before you set it into the environment.
  • SEND_CONFIRMATION_EMAIL (default: True)
    • Description: If turned on, the register or activation REST endpoint or mutation will send a confirmation email to the user.
    • Type: bool
  • PASSWORD_RESET_CONFIRM_URL (default: reset_password?uid={uid}&token={token})
    • Description: URL to your frontend password reset page. It should contain {uid} and {token} placeholders. You should pass uid and token to reset the password confirmation REST endpoint or mutation.
    • Type: str
    • Warning: In order to use unsafe characters you have to encode with urllib.parse.encode before you set it into the environment.
  • PASSWORD_CHANGED_EMAIL_CONFIRMATION (default: True)
    • Description: If turned on, change password REST endpoints or mutations will send a confirmation email to the user.
    • Type: bool

Social Auth Settings

This project uses python-social-auth to easily set up social authentication and authorization mechanisms. This project only supports a limited amount of social networks such as Facebook, Github, Google, LinkedIn, and Twitter. If you want to add more common social networks, feel free to create an issue or pull request.

SOCIAL_AUTH_BACKENDS (default: [])

  • Description: The list of social auth backends to use in the app.
  • Type: list (FOO=a,b,c)
  • Possible list values: social_core.backends.facebook.FacebookOAuth2, social_core.backends.github.GithubOAuth2, social_core.backends.google.GoogleOAuth2, social_core.backends.linkedin.LinkedinOAuth2, social_core.backends.twitter.TwitterOAuth

For the social auth backends that you've chosen to use, please set the corresponding environment variables of keys and secrets into the application. You can find the name of the environment variables in the python-social-auth documentation.

Clone this wiki locally