Demo application has the second part only
Final application is deplyed on heroku Admin Link
username: admin
password: pass1234
The development steps and their results are documented in the file RESULTS.md
You should have the following installed in order to run the application:
- Python
- Poetry
- PostgreSQL (local or remote)
Run the following terminal command in order to clone the app and go into its directory.
git clone https://gitlab.com/mustafa.abdelrahman/django-training.git && cd django-training
While in the root directory (django-training), run the following command to use the poetry environment
poetry shell
Or you can list all the available virtual environments with the command poetry env list --full-path
, then copy the path of the virtual environment you want to use and run the following command with the path instead of /full/path/to/python
poetry env use /full/path/to/python
Run the following terminal command in order to install the app
poetry install
In djmusic directory, change the name of the .env.example file to .env
Fill the .env file with the database credentails, and the secret key of the app.
You can generate a secret key with either of the following commands
openssl rand -base64 32
head -c 32 /dev/urandom | base64
To be safe, store the secret key in the .env file inside the quotations marks.
In the root (django-training) directory. Run the following code to prepare the database migrations
poetry run python djmusic/manage.py makemigrations
Then run the following command to apply the migrations
poetry run python djmusic/manage.py migrate
In order to create a super user, run the following command and enter the credentials interactively
poetry run python djmusic/manage.py createsuperuser
In order to run the created endpoint tests, run the following command
poetry run pytest
A message with the testing result, percentage, passing tests, and time will be printed.
Run the following comman to start serving the application
poetry run python djmusic/manage.py runserver
If port 8000 is busy, try running on another port of your choice as follows
poetry run python djmusic/manage.py runserver 8080
You can replace 8080 with the port you wish.
Now visit http://localhost:8000 or http://localhost:8080 or replace 8000 with the port you have specified while running the server
You can visit the admin panel using this link http://localhost:8000/admin Now you can login using the credentials you created in the previous section
These Views do not work anymore after the sixth part
Artists and albums can be created using the following links, repectively.
Artist: http://localhost:8000/artists/create/
Starting with the fifth part, the artist's view endpoints are followed by /old/ because a serialized REST API view was linked to the original endpoint
List View: http://localhost:8000/artists/old/create/
Album: http://localhost:8000/albums/create/
These Views do not work anymore after the sixth part
A list view of the artists and their respective albums can be viewed using the following link.
List View: http://localhost:8000/artists/
Starting with the fifth part, the artist's view endpoints are followed by /old/ because a serialized REST API view was linked to the original endpoint
List View: http://localhost:8000/artists/old/
This View does not work anymore after the sixth part
Using the following links, you can:
Two rest-api endpoints were added to the application.
-
Artist View (JSON): GET http://localhost:8000/artists/
Data will be returned in the following format[ { "id": '<id>', // Numeric "stage_name": "<stage_name>", // String "social_link": "<social_link>" // String }, ... ]
-
Artist Creation (JSON body): POST http://localhost:8000/artists/
Requires authentication as Basic Authentication (username and password) along with the request
Requires a body with the following keys
- stage_name: required, unique, max length of 200 characters
- social_link: optional
Data will be returned in the following format
{ "id": '<id>', // Numeric "stage_name": "<stage_name>", // String "social_link": "<social_link>" // String }
-
Register: POST http://localhost:8000/authentication/register/
It accepts a body with the following fields- username: required, unique
- email: optional, unique
- password1: require, strong password
- password2: matches password1
It returns a json with the following format
{ "username": "<username>", "email": "<email>" }
-
Login: POST http://localhost:8000/authentication/#/
It accepts a body with the following fields- username: required
- password: required
It returns a json with the following format
{ "token": "<knox token>", "user": { "id": '<id>', // Numeric "username": "<username>", "email": "<email>", "bio": "<bio>" } }
-
Logout: POST http://localhost:8000/authentication/logout/
It requires an authorization header with in the following formatAuthorization: Token token_here
-
Retrieve User: GET http://localhost:8000/users/int:pk/
It returns a json with the following format{ "id": '<id>', "username": "<username>", "email": "<email>", "bio": "<bio>" }
-
Update the whole user: PUT http://localhost:8000/authentication/#/
It accepts a body with the following required fields
- username: required
It accepts a body with the following optional fields
- bio
It requires an authorization header with in the following format
Authorization: Token token_here
It returns a json with the following format
{ "id": '<id>', "username": "<username>", "email": "<email>", "bio": "<bio>" }
-
Update specific user fields: PUT http://localhost:8000/authentication/#/ It accepts a body with any (or all) the following optional fields
- username
- bio
It requires an authorization header with in the following format
Authorization: Token token_here
It returns a json with the following format
{ "id": '<id>', "username": "<username>", "email": "<email>", "bio": "<bio>" }