Setup and Installation
pyenv and Python version instllation:
Linux/WSL: (Debian/Ubuntu)
curl -fsSL <https://pyenv.run> | bash
sudo apt update
sudo apt install build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev curl git libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-devMacOS:
brew update
brew install pyenv
brew install openssl readline sqlite3 xz zlib tcl-tk@8
Further setup:
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init - zsh)"' >> ~/.zshrcClose and reopen terminal
pyenv install 3.13
pyenv global 3.13
Create a virtual environment: python3 -m venv venv_py_{version number}
Activate virtual environment: source venv/bin/activate
Install pipx
Link to pipx installation instructions: https://pipxproject.github.io/pipx/installation/
(Outside of the project directory)
Install Poetry (dependancy manager): pipx install poetry
(Inside the project directory) Install dependencies:
poetry lock && poetry installRunning the Project
Apply database migrations: python3 manage.py migrate
Create a superuser (for admin access): python3 manage.py createsuperuser
Start the development server: python3 manage.py runserver
Default Endpoints
Admin interface: http://127.0.0.1:8000/admin/
API test endpoint: http://127.0.0.1:8000/api/test/
Project Structure: codefire_python_backend/ ├── api/ # API application ├── codefire_python_backend/# Django project settings ├── manage.py # Django management script └── db.sqlite3 # SQLite database
- Create a file named
.env.localin the root directory of your project. - Add your local secret values to the
.env.localfile. For example:
DO NOT add secrets to the .env file in the root directory. This file is for non-sensitive values only.
BEFORE TESTING: If database changes have been made, run migrations to apply session related database changes.
Use Postman to access application endpoints:
Authorization: Make a GET request to the base URL every time a new request is made to get a new CSRF token.
Key: X-CSRFToken
Value: token
Sign Up
POST
<http://127.0.0.1:8000/api/auth/signup>
Body:
{
"username": "",
"email": "",
"password": ""
}
Login
POST
<http://127.0.0.1:8000/api/auth/login>
Body:
{
"username": "",
"password": ""
}These last two endpoints use a X-CSRFToken to authorize the action.
Check Session
GET
<http://127.0.0.1:8000/api/auth/check_session>
Body:
{}
Logout
POST
<http://127.0.0.1:8000/api/auth/logout>
Body:
{}