Friendly (Live)
Welcome to the repository for our Django application, Friendly! This README serves as your guide on setting up the application. We offer two setups for your convenience: the Dockerized setup and the Manual setup. The Dockerized setup is ideal for deployment purposes and running the application. The Manual setup is ideal for the development environment. Combining these setups ensures a seamless deployment and development experience. Follow the steps below to get started.
-
Clone the repository:
git clone https://github.com/DubeyAkshat/friendly.git
-
Navigate to the
friendly
directory:cd friendly
-
Create a
.env
file in thefriendly
directory. It is advisable to refer to the.env.example
and create the environment variables. For a quick setup, you can copy the environment variables given below:DEBUG=False SECRET_KEY=my_secret_key DJANGO_ALLOWED_HOSTS=localhost,127.0.0.1,[::1] POSTGRES_USER=friendly POSTGRES_PASSWORD=friendly POSTGRES_HOST=postgres_db POSTGRES_DB=friendly POSTGRES_PORT=5432 NGINX_HOST_PORT=80
Replace the
SECRET_KEY
with a securely generated secret key for your Django application. You can use online tools or Django'sdjango.core.management.utils.get_random_secret_key()
method to generate a new key. Make sure to keep this key confidential and never share it publicly. Also, you can add your production domain or IP address to theDJANGO_ALLOWED_HOST
if you intend to deploy the application. -
Build the docker images and start the docker containers in daemon mode:
docker-compose up --build -d
This command will build the Docker image and start the application along with its dependencies.
-
Access the application at
http://localhost
if theNGINX_HOST_PORT
environment variable is set to80
. In case you've modified theNGINX_HOST_PORT
to a different value, the application can be reached athttp://localhost:{NGINX_HOST_PORT}
, or through the configured domains in theDJANGO_ALLOWED_HOSTS
environment variable. -
Run migrations:
docker-compose exec django_app python manage.py migrate
-
You can create a
superuser
by using the command:docker-compose exec django_app python manage.py createsuperuser
Afterward, access the admin interface at the configured base URL, either directly (
http://localhost/admin/
orhttp://localhost:{NGINX_HOST_PORT}/admin/
) or through the specified domain(s) in theDJANGO_ALLOWED_HOSTS variable
. -
To stop the containers and the application:
docker-compose down
If you prefer not to use Docker, you can manually set up and run the application or use this setup as development environment using the following steps:
-
Database setup:
- Install PostgreSQL
- Create user, database and role for the application:
- Open a PostgreSQL shell or use a tool like pgAdmin
- Run the following commands to create a user, a database, and a role for your Django application. Replace
<user>
,<password>
,<host>
,<port>
, and<database>
with your preferred values:CREATE USER <user> WITH PASSWORD '<password>'; CREATE DATABASE <database> OWNER <user>; ALTER ROLE <user> SET client_encoding TO 'utf8'; ALTER ROLE <user> SET default_transaction_isolation TO 'read committed'; ALTER ROLE <user> SET timezone TO 'UTC'; GRANT ALL PRIVILEGES ON DATABASE <database> TO <user>;
-
Clone the repository:
git clone https://github.com/DubeyAkshat/friendly.git
-
Navigate to the
friendly
directory:cd friendly
-
Create a virtual environment:
python -m venv venv
-
Activate the virtual environment:
source venv/bin/activate
- On Windows:
.\venv\Scripts\Activate.ps1`
- On Windows:
-
Create a
.env
file in thefriendly
directory. It is advisable to refer to the.env.example
and create the environment variables. For a quick setup, you can copy the environment variables given below:DEBUG=True SECRET_KEY=my_secret_key DJANGO_ALLOWED_HOSTS=localhost,127.0.0.1,[::1] DATABASE_URL=postgres://<user>:<password>@<host>:<port>/<database>
Replace the
SECRET_KEY
with a securely generated secret key for your Django application. You can use online tools or Django'sdjango.core.management.utils.get_random_secret_key()
method to generate a new key. Make sure to keep this key confidential and never share it publicly. Replace<user>
,<password>
,<host>
,<port>
&<database>
with the actual values in theDATABASE_URL
-
Install dependencies:
pip install -r requirements.txt
-
Run migrations:
python manage.py makemigrations python manage.py migrate
-
Collect static files:
python manage.py collectstatic --noinput --clear
-
Run the application:
Navigate to thefriendly/django_app/
directory and start the server.- With Gunicorn:
OR
gunicorn friendly_django.wsgi:application --bind 0.0.0.0:8000 --reload
- Without Gunicorn:
python manage.py runserver
Access the application at
http://localhost:8000
or through the configured domains in theDJANGO_ALLOWED_HOSTS
environment variable. - With Gunicorn:
-
To create a
superuser
:python manage.py createsuperuser
Afterward, access the admin interface at the configured base URL, either directly (
http://localhost:8000/admin/
) or through the specified domain(s) in theDJANGO_ALLOWED_HOSTS
variable. -
To stop the Django development server, simply press
Ctrl+C
in the terminal where the server is running.