Skip to content

Setting up your Django project locally

Warning

This guide is intended for a Linux-based OS

Procedure

  1. git clone your django project locally.
  2. Verify that Python3 is installed on your system (ideally version>=3.8).
  3. Create a database:
    • If using an SQlite3 database (Django's default), it will be automatically created for you by Django in the following steps.
    • If using PostgreSQL:
      • Install PostgreSQL natively (e.g. for Ubuntu, instructions here).
      • Add a password for the postgres user as per the instructions above.
      • Create the database:
        • Connect: psql -U postgres
        • CREATE DATABASE <database name>; where <database name> is the database name specified in Django's settings, or .env file, e.g. mlplayground_development.
      • [Optional] Install pgadmin4 for administering it.
  4. A virtual environment. Example setup:
    1. cd to your project's root.
    2. python3 -m venv venv
  5. Activate the virtual environment:
    • source venv/bin/activate
  6. Install requirements:
    • python -m pip install -r requirements.txt (once the venv is activated you don't need to specifically run python3, just python).
  7. Make sure you have an .env file with all the required project variables in your project's root.
  8. Create the database structure:
    • python manage.py migrate --run-syncdb
  9. Create a superuser:
    • python manage.py createsuperuser
  10. Run the developement server: python3 manage.py runserver. By default, you should be able to access http://localhost:8000.
    • If you want to run with HTTPS:
      • pip install Werkzeug
      • python manage.py runserver_plus --cert cert

Why PostgreSQL?

PostgreSQL supports features that are unavailable to other databases, such as ArrayFields.

Logging in

When running the project locally, CERN SSO will not be functioning by default. One way to login is to use the superuser you created to login to the app. If you need to test the SSO, make sure that:

  • You have added the correct Redirect URI in the SSO registrion in the Application portal (i.e. https://localhost:8000/accounts/cern/login/callback/)
  • Run the local server with HTTPS just in case.

Usual workflow

The setup procedure needs to be followed only once, usually. For usual developement, you will only need to run steps 5 and 10.