This repository contains a Bash script to automate the creation and setup of a Django project. The script handles the creation of the Django project, apps, virtual environment, and basic Docker configuration. It streamlines repetitive setup tasks, making it faster and easier to start new Django projects.
- Automatically creates a Django project by asking for the project name.
- Sets up a virtual environment (
venv) and installs dependencies.
- Prompts to create an initial app (
accounts) with:- Directory structure for
api/v1. - Essential files like
urls.py,serializers.py,views.py, and more.
- Directory structure for
- Allows adding multiple apps in a loop with proper URL configuration and addition to
INSTALLED_APPS.
- Optionally creates a
Dockerfilefor containerizing the Django project. - Optionally generates a
docker-compose.ymlfor quick containerized setup.
- Dynamically updates:
INSTALLED_APPSinsettings.py.urlpatternsinurls.pywith app-specific routes.
- Prevents duplicate entries in settings or URLs.
-
Clone this repository:
git clone https://github.com/hosseinpk/Django-Project-structure.git
-
Ensure you have the following installed:
- Python 3.7 or higher.
- Bash shell (Linux/macOS or Git Bash on Windows).
-
Install required Python packages: Add your Python dependencies in a
requirements.txtfile (if not already provided).
-
Set permission:
chmod +x setup_django_project.sh
or
chmod +x django_creator_final.sh
-
Run the script:
source setup_django_project.shor
source django_creator_final.sh -
Follow the prompts:
- Enter the Django project name.
- Choose whether to create an initial
accountsapp. - Optionally add more apps in a loop.
- Decide whether to generate a
Dockerfileand/ordocker-compose.yml.
After running the script, your project may look like this:
project_name/
├── accounts/
│ ├── api/
│ │ └── v1/
│ │ ├── serializers.py
│ │ ├── urls.py
│ │ ├── validators.py
│ │ └── views.py
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── migrations/
│ ├── models.py
│ ├── tests.py
│ └── urls.py
├── project_name/
│ ├── __init__.py
│ ├── asgi.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── manage.py
├── Dockerfile
├── docker-compose.yml
└── requirements.txt
Contributions are welcome! To contribute:
- Fork the repository.
- Create a feature branch:
git checkout -b feature-name
- Commit your changes:
git commit -m "Add feature description" - Push to the branch:
git push origin feature-name
- Open a pull request.
This project is licensed under the MIT License.
If you encounter any issues or have suggestions, feel free to open an issue or submit a pull request.
Happy coding! 🚀