Setting up your Django project locally
Warning
This guide is intended for a Linux-based OS
Procedure
git clone
your django project locally.- Verify that Python3 is installed on your system (ideally version>=3.8).
- 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
.
- Connect:
- [Optional] Install pgadmin4 for administering it.
- A virtual environment. Example setup:
cd
to your project's root.python3 -m venv venv
- Activate the virtual environment:
source venv/bin/activate
- Install requirements:
python -m pip install -r requirements.txt
(once the venv is activated you don't need to specifically runpython3
, justpython
).
- Make sure you have an
.env
file with all the required project variables in your project's root. - Create the database structure:
python manage.py migrate --run-syncdb
- Create a superuser:
python manage.py createsuperuser
- 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
- If you want to run with HTTPS:
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.