How to Use
- Install Devbox
- Run
devbox shellto install your packages and run the init_hook. This will activate your virtual environment and install Django. - Initialize PostgreSQL with
devbox run initdb. - In the root directory, run
devbox run create_dbto create the database and run your Django migrations. - In the root directory, run
devbox run serverto start the server. You can access the Django example atlocalhost:8000.
How to Create this Example from Scratch
Setting up the Project
- Install Devbox.
-
Run
devbox initto create a new Devbox project in your directory. -
Install Python and PostgreSQL with
devbox install python python310Packages.pip openssl postgresql. This will also install the Devbox plugins for pip (which sets up your .venv directory) and PostgreSQL. -
Copy the requirements.txt and
todo_projectdirectory into the root folder of your project -
Start a devbox shell with
devbox shell, then activate your virtual environment and install your requirements using the commands below.You can also add these lines to yourinit_hookto automatically activate your venv whenever you start your shell
Setting up the Database
The Django example uses a Postgres database. To set up the database, we will first create a new PostgreSQL database cluster, create thetodo_db and user, and run the Django migrations.
-
Initialize your Postgres database cluster with
devbox run initdb. -
Start the Postgres service by running
devbox services start postgres -
In your
devbox shell, create the emptytodo_dbdatabase and user with the following commands.You can add this as a devbox script in yourdevbox.jsonfile, so you can replicate the setup on other machines. -
Run the Django migrations to create the tables in your database.
devbox.json if
you want to automate them for future use. See create_db in the projects devbox.json for an
example.