git clone https://github.com/javohir-swe/drf.git
cd drf
- Installing PostgreSQL
- You can install PostgreSQL with the following command in the terminal.
sudo apt-get update
sudo apt-get install python-pip python-dev libpq-dev postgresql postgresql-contrib
- On macOS, you can install posgresql in the terminal with brew:
brew install postgresql
- Now, you may start up postresql after its installation with the following command.
brew services start postgresql
- If you use a Windows machine, you can download a compatible PostgreSQL installer from the official website of PostgreSQL.
-
As part of the installation, PostgreSQL already created a user, postgres by default for carrying out administrative responsibilities. We shall change to the user to create our database and new user.
sudo su - postgres
-
psql
gives us access to the Postgres interactive terminal where we can use the PostgreSQL queries.psql
-
Now, we shall create a database for this project. Always make sure to create a separate database for each project you work on.
CREATE DATABASE mydb;
-
In the above command, we have used the CREATE command in SQL to create our database which we named mydb. We also ended the line with a semi-colon which comes after every command in SQL.
-
Creating a Database User
-
Now, we shall create a database user for our database. We will call the user
myuser
. Replacepassword
with a strong password below.CREATE USER myuser WITH PASSWORD 'password';
-
Let us now grant access rights to our new user to enable it to work on the database.
GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;
-
We can then exit the current user's shell session and get back to the postgres user's session
\q
-
Now, let us leave the PostgreSQL interactive terminal back to the terminal.
exit
cp .env.example .env
-
Build and start Docker containers:
docker-compose up --build
-
If you want you can create database migrations:
docker-compose exec web python manage.py makemigrations docker-compose exec web python manage.py migrate
-
Create a superuser account:
docker-compose exec web python manage.py createsuperuser
- Create a Virtual Environment activate it:
python3 -m venv venv
source venv/bin/activate
- Migrate
python3 manage.py migrate
- Create Superuser account
python3 manage.py createsuperuser
- And then run the project
If the result is as shown below, congratulations, you have successfully launched the project. 🎉 If there is any error, let ChatGPT help you )
python3 manage.py runserver
Watching for file changes with StatReloader Performing system checks... System check identified no issues (0 silenced). December 18, 2024 - 16:48:14 Django version 5.1.4, using settings 'core.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C.
After successful installation, you can access:
- API Documentation: http://localhost:8000/swagger/
- Django Admin: http://localhost:8000/admin/
- API Endpoints: http://localhost:8000/api/
- Custom User Authentication
- JWT Token Authentication
- Swagger Documentation
- RESTful API Endpoints