├── EasyDjango Example.gif ├── LICENSE ├── README.md ├── easydjango ├── __init__.py ├── cli.py ├── project_setup.py ├── settings_updater.py ├── superuser_creator.py ├── template_creator.py ├── url_creator.py └── view_creator.py └── setup.py /EasyDjango Example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghaithheni/easydjango/e8a4edc55e38af217006745c6c6ea6bb92a07149/EasyDjango Example.gif -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Ghaith Heni 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | 1. The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | 2. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Easy Django Project Setup Tool 2 | 3 | EasyDjango is a command-line tool for quickly setting up a new Django project with customizable options, including app creation, templates, static files, and superuser setup. 4 | 5 | [**Click here for a Demo**](#usage) 6 | 7 | ## Features 8 | 9 | - Create a new Django project and app with minimal commands. 10 | - Optionally include Tailwind CSS for styling (by adding the argument `--tailwind`). 11 | - Automatic creation of necessary directories for templates, static files, and media. 12 | - Create a superuser during setup. 13 | - Colorful and user-friendly CLI prompts. 14 | 15 | ## Installation 16 | 17 | You can install QuickDjango via pip. First, ensure you have Python and pip installed, then run: 18 | 19 | ```bash 20 | pip install easydjango-project 21 | ``` 22 | 23 | > **Note**: The installation command is the same for Windows, macOS, and Linux, but you might need to use pip3 instead on some operating systems. 24 | 25 | ## Usage 26 | 27 | To create a new Django project, execute the following easy command: 28 | 29 | ```bash 30 | easydjango 31 | ``` 32 | 33 | You will be prompted to provide the following information: 34 | 35 | Project Name (default: `myproject`) 36 | App Name (default: `myapp`) 37 | Superuser Username (default: `admin`) 38 | Superuser Password (default: `admin`) 39 | 40 | 41 | ## Demonstration 42 | 43 |  44 | 45 | ## Support This Project 46 | 47 | If you find this project useful and would like to support its continued development, consider making a donation. Your contributions will help cover expenses for development tools and other resources. 48 | 49 | [](https://gateway.konnect.network/me/ghaithheni) 50 | [](https://www.buymeacoffee.com/ghaithheni) 51 | 52 | Thank you for your support! Every contribution, no matter how small, makes a difference! 53 | 54 | ## Contributing 55 | 56 | If you'd like to contribute to EasyDjango, feel free to fork the repository and submit a pull request. Any contributions are welcome! 57 | 58 | ## License 59 | 60 | This project is licensed under the [MIT License](LICENSE). See the LICENSE file for details. 61 | 62 | ## Acknowledgements 63 | 64 | Django for being an awesome web framework. 65 | Colorama for colorful terminal text. 66 | 67 | ## Contact 68 | 69 | For inquiries or feedback, please reach out at [elghaithheni@gmail.com](mailto:elghaithheni@gmail.com). 70 | -------------------------------------------------------------------------------- /easydjango/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghaithheni/easydjango/e8a4edc55e38af217006745c6c6ea6bb92a07149/easydjango/__init__.py -------------------------------------------------------------------------------- /easydjango/cli.py: -------------------------------------------------------------------------------- 1 | from .project_setup import create_django_project 2 | from colorama import init, Fore, Style 3 | import getpass 4 | 5 | init(autoreset=True) 6 | 7 | def print_success(message): 8 | print(Fore.GREEN + message + Style.RESET_ALL) 9 | 10 | def print_error(message): 11 | print(Fore.RED + message + Style.RESET_ALL) 12 | 13 | def print_warning(message): 14 | print(Fore.YELLOW + message + Style.RESET_ALL) 15 | 16 | def print_info(message): 17 | print(Fore.BLUE + message + Style.RESET_ALL) 18 | 19 | def interactive_prompt(): 20 | print_info("Welcome to the EasyDjango Project Setup!") 21 | project_name = input(Fore.CYAN + "Enter the name of your Django project (default: myproject): " + Style.RESET_ALL) or "myproject" 22 | app_name = input(Fore.CYAN + "Enter the name of your Django app (default: myapp): " + Style.RESET_ALL) or "myapp" 23 | username = input(Fore.CYAN + "Enter the superuser username (default: admin): " + Style.RESET_ALL) or "admin" 24 | password = getpass.getpass(Fore.CYAN + "Enter the superuser password (default: admin): " + Style.RESET_ALL) or "admin" 25 | return project_name, app_name, username, password 26 | 27 | def main(): 28 | project_name, app_name, username, password = interactive_prompt() 29 | try: 30 | create_django_project(project_name, app_name, False, username, password) 31 | except Exception as e: 32 | print_error(f"Error during project setup: {e}") 33 | 34 | if __name__ == '__main__': 35 | main() 36 | -------------------------------------------------------------------------------- /easydjango/project_setup.py: -------------------------------------------------------------------------------- 1 | import os 2 | import subprocess 3 | from .settings_updater import update_settings 4 | from .url_creator import create_app_urls, update_project_urls 5 | from .template_creator import create_templates 6 | from .view_creator import create_home_view 7 | from .superuser_creator import create_superuser 8 | from colorama import Fore, Style 9 | import sys 10 | 11 | def print_progress(message): 12 | print(Fore.BLUE + message + Style.RESET_ALL) 13 | 14 | def print_success(message): 15 | print(Fore.GREEN + message + Style.RESET_ALL) 16 | 17 | def print_error(message): 18 | print(Fore.RED + message + Style.RESET_ALL) 19 | 20 | def create_django_project(project_name, app_name, use_tailwind, username, password): 21 | try: 22 | print_progress("Creating the Django project...") 23 | subprocess.run(['django-admin', 'startproject', project_name], check=True) 24 | 25 | os.chdir(project_name) 26 | print_progress("Creating the Django app...") 27 | subprocess.run([sys.executable, 'manage.py', 'startapp', app_name], check=True) 28 | 29 | print_progress("Creating necessary directories for static, media, and templates...") 30 | for directory in ['templates', 'static', 'media']: 31 | os.makedirs(directory, exist_ok=True) 32 | 33 | print_progress("Updating settings and URLs...") 34 | update_settings(project_name, app_name) 35 | create_app_urls(app_name) 36 | update_project_urls(project_name, app_name) 37 | 38 | print_progress("Creating templates and views...") 39 | create_templates(app_name, project_name, use_tailwind) 40 | create_home_view(app_name) 41 | 42 | print_progress("Running migrations...") 43 | subprocess.run([sys.executable, 'manage.py', 'migrate'], check=True) 44 | 45 | print_progress("Creating the superuser...") 46 | create_superuser(username, password) 47 | 48 | print_success(f'Django project "{project_name}" created successfully with app "{app_name}" and superuser "{username}".') 49 | 50 | except FileNotFoundError: 51 | print_error("Error: 'django-admin' command not found. Is Django installed?") 52 | except ValueError as ve: 53 | print_error(f"Input error: {ve}") 54 | except Exception as e: 55 | print_error(f"An unexpected error occurred: {e}") 56 | -------------------------------------------------------------------------------- /easydjango/settings_updater.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | def update_settings(project_name, app_name): 4 | settings_path = os.path.join(project_name, 'settings.py') 5 | 6 | with open(settings_path, 'a') as settings_file: 7 | settings_file.write("import os\n") 8 | 9 | # Add the app to INSTALLED_APPS 10 | settings_file.write(f"\nINSTALLED_APPS.append('{app_name}')\n") 11 | 12 | # Add media settings 13 | settings_file.write("\nMEDIA_URL = '/media/'\nMEDIA_ROOT = os.path.join(BASE_DIR, 'media')\n") 14 | 15 | # Add static settings 16 | settings_file.write("\nSTATIC_URL = '/static/'\nSTATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]\n") 17 | 18 | # Add STATIC_ROOT setting 19 | settings_file.write("STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')\n") 20 | 21 | # Update the TEMPLATES setting to include the root templates directory 22 | settings_file.write( 23 | "\nTEMPLATES[0]['DIRS'].append(os.path.join(BASE_DIR, 'templates'))\n" 24 | ) 25 | -------------------------------------------------------------------------------- /easydjango/superuser_creator.py: -------------------------------------------------------------------------------- 1 | import django 2 | import os 3 | import sys 4 | 5 | def setup_django(): 6 | current_dir = os.getcwd() 7 | project_name = os.path.basename(current_dir) 8 | 9 | settings_module = f"{project_name}.settings" 10 | 11 | sys.path.append(current_dir) 12 | 13 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', settings_module) 14 | django.setup() 15 | 16 | def create_superuser(username, password): 17 | try: 18 | setup_django() 19 | 20 | from django.contrib.auth import get_user_model 21 | User = get_user_model() 22 | 23 | if not User.objects.filter(username=username).exists(): 24 | user = User.objects.create_superuser( 25 | username=username, 26 | email="admin@example.com", 27 | password=password 28 | ) 29 | print(f'Superuser "{username}" created successfully.') 30 | else: 31 | print(f'Superuser "{username}" already exists.') 32 | except Exception as e: 33 | print(f'An unexpected error occurred: {e}') 34 | -------------------------------------------------------------------------------- /easydjango/template_creator.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | def create_templates(app_name, project_name, use_tailwind): 4 | templates_dir = os.path.join(os.getcwd(), 'templates') 5 | os.makedirs(templates_dir, exist_ok=True) 6 | print(f"Templates directory: {templates_dir}") 7 | 8 | tailwind_script = ( 9 | ' \n' if use_tailwind else '' 10 | ) 11 | 12 | base_html_content = f""" 13 | 14 |
15 | 16 | 17 |Congratulations! You have successfully set up your Django project using EasyDjango.
74 |{app_name}/views.py
) to customize your application logic.{app_name}/urls.py
) to define your app's URL patterns.templates
directory to change your site’s layout and design./admin
after running the development server.If you have any questions or need assistance, feel free to reach out at elghaithheni@gmail.com.
84 |