This guide provides comprehensive instructions for setting up and running the Django API for our project. Follow these steps meticulously to ensure proper configuration and operation of the API on your local environment.
- Python 3.10+: Ensure Python version 3.10 or higher is installed. If not, download and install it from Python's official website.
- Git: Verify Git is installed for cloning the repository. Download Git from Git's official website.
- Virtual Environment: Basic knowledge of virtual environment creation and management is assumed.
-
Open your terminal or command prompt.
-
Clone the repository with the following command:
git clone https://github.com/your_username/your_repository.git
Replace
https://github.com/your_username/your_repository.git
with the URL of your GitHub repository. -
Change to the project directory:
cd your_project_directory
Replace
your_project_directory
with the name of your cloned project directory.
-
Create a Virtual Environment
To isolate the project dependencies, create a virtual environment by executing:
python -m venv venv
This command generates a virtual environment named
venv
. -
Activate the Virtual Environment
-
Windows
venv\Scripts\activate
-
macOS/Linux
source venv/bin/activate
-
-
Install Dependencies
With the virtual environment activated, install the required project dependencies:
pip install -r requirements.txt
-
Create a
.env
FileIn the root directory of the project, create a file named
.env
and add the necessary environment variables. Example content includes:DEBUG=True SECRET_KEY=your_secret_key DATABASE_URL=your_database_url
Ensure you replace
your_secret_key
andyour_database_url
with appropriate values.
Execute the following commands to configure the database schema:
-
Make Migrations
python manage.py makemigrations
-
Apply Migrations
python manage.py migrate
Start the Django development server with:
python manage.py runserver
This will launch the server and you should see output indicating it is running on http://127.0.0.1:8000/
.
-
Access the API
Open a web browser or API client (e.g., Postman) and navigate to
http://127.0.0.1:8000/
to view the available API endpoints. -
Explore Endpoints
Use Django’s default web interface or API documentation to explore the endpoints.
To halt the Django development server, return to your terminal and press Ctrl+C
.
To synchronize with the latest changes from the repository:
-
Pull Latest Changes
git pull origin main
Replace
main
with the relevant branch name if different. -
Install New Dependencies
If new dependencies have been added, install them using:
pip install -r requirements.txt
-
Apply New Migrations
Execute the migration commands if there are new changes:
python manage.py migrate
- Network Errors: Confirm that the virtual environment is activated and dependencies are properly installed.
- Database Issues: Verify the
.env
file contains the correctDATABASE_URL
settings. - Permission Issues: Ensure commands are executed with appropriate permissions or consult system administration.
For further assistance, consult the Django documentation or seek help from team members.
Contributions to the project are welcome. Please submit a pull request with your changes and adhere to the project's contribution guidelines outlined in the repository.