- Python v3.6.7
- pip v19.0.3
- PostgreSQL v11.2
-
First install DevSpaces client application, follow the instructions here to do this.
-
Clone this repository locally
-
To create a DevSpace, open a terminal then navigate to the cloned repository directory and run following command
devspaces create
This will open a build status window and shows you the progress of DevSpace creation. Once build is successful validated starts.
-
Once validation is completed. Run
devspaces ls
command to see the list of DevSpaces and corresponding status. Newly created DevSpacepython-postgres
will be in "Stopped" status. -
To start your DevSpace run following command
devspaces start python-postgres
You will receive a notification when your DevSpace is ready to be used.
- To get inside your DevSpace, run following command
devspaces exec python-postgres
- From a new terminal, clone the demo application repository
git clone https://github.com/JumboCode/django-postgres-tutorial.git
- Navigate to cloned demo application directory
cd django-postgres-tutorial
- To synchronization code from your local machine to your DevSpace. Run following command
devspaces bind python-postgres
This will synchronize files from your current working directory to your DevSpace. It might takes some time to complete, depending on the repository size.
- Get inside your DevSpace by running following command
devspaces exec python-postgres
-
Once you're inside DevSpace, you should be able see
django-postgres-tutorial
project files under/data
directory. -
Install dependencies
pip install -r requirements.txt
- Prepare database
su postgres
psql
CREATE DATABASE djangotutorial;
CREATE USER djangotutorial WITH PASSWORD 'supersecret';
GRANT ALL PRIVILEGES ON DATABASE "djangotutorial" to djangotutorial;
\q
exit
- export ENV variable.
export DJANGO_SETTINGS_MODULE=django_postgres_example.settings.dev
- Run migrations
python3 manage.py makemigrations
python3 manage.py migrate
- Add
.devspaces.io
toALLOWED_HOSTS
variable indjango_postgres_example/settings/dev.py
. This can be done from your local machine as well and change will be synchronized to DevSpace. After change it looks like this
ALLOWED_HOSTS = ['localhost', '.devspaces.io']
- Run the demo project
python3 manage.py runserver 0.0.0.0:80
Now run following command from your local terminal devspaces info python-postgres
. URL under URLs section is the public URL to your running application. Append api/sleds/
to the URL to see it is working e.g. http://python-postgres.<username>.devspaces.io:<port>/api/sleds/