Skip to content

Chris-sle/Django.py_API_Template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django API Template

This is a simple template for creating RESTful APIs with Django and Django REST Framework.

Features

  • Simple structure for organizing Django apps and REST API
  • Basic setup with model, serializer, view, and routing
  • Support for environment variable configuration

Project Structure

django-api-template/
├── django_api_template/   # Main Django project directory
│   ├── __init__.py
│   ├── settings.py        # Configuration for your Django project
│   ├── urls.py            # URL routing
│   ├── wsgi.py            # WSGI application for deployment
├── api/                   # Django app containing the API logic
│   ├── migrations/        # Database migrations
│   ├── __init__.py
│   ├── admin.py           # Admin panel configuration
│   ├── apps.py            # App configuration
│   ├── models.py          # Database models
│   ├── serializers.py     # Serializers for converting data
│   ├── tests.py           # Unit tests for the app
│   └── views.py           # API views
├── manage.py              # Command-line utility for Django
├── .env                   # Environment variables
├── requirements.txt       # Python package dependencies
├── .gitignore             # Files to be ignored by Git
└── README.md              # Project documentation

Getting Started

Prerequisites

  • Python 3.x: Download from python.org.
  • pip: Comes with Python; ensure it’s updated.

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/django-api-template.git
    cd django-api-template
  2. Create and activate a virtual environment:

    python -m venv venv   # Create virtual environment
    # Activate the virtual environment
    # Windows
    venv\Scripts\activate
    # macOS/Linux
    source venv/bin/activate
  3. Install requirements:

    pip install -r requirements.txt
  4. Set up environment variables:

    Create a .env file in the root directory (or modify the existing one) to configure any necessary environment variables:

    SECRET_KEY=your-secret-key
    DEBUG=True
    

Running the Application

  • To run the Django development server, use:

    python manage.py runserver

    The application will be accessible at http://127.0.0.1:8000/ by default.

Adding Models and APIs

  • To add new models and APIs, create them in the api/models.py, api/serializers.py, and api/views.py files. Be sure to also update the routes in urls.py.

Database Migrations

  • After creating or modifying models, run the following commands to create and apply database migrations:

    python manage.py makemigrations
    python manage.py migrate

Testing

  • You can create tests for your application in the api/tests.py. Run your tests with:

    python manage.py test

Usage

Modify and expand this template for your project needs. Ensure to update the CORS settings and API routes as per your application's requirements.

Contributing

Feel free to fork this repository, make enhancements, and submit pull requests. Contributions are welcome to improve features and add new ones.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages