Skip to content

A quickstart tool for creating a Django project with TailwindCSS, Flowbite, HTMX, and AlpineJS.

License

Notifications You must be signed in to change notification settings

Achronus/django_project_quickstart_tool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django Project Quickstart Tool

Welcome to the quick setup tool for creating a Django project with the following stack:

The default pip packages installed include:

  • django
  • django-compressor
  • django-browser-reload
  • django-htmx
  • python-dotenv

Note: all libraries and packages are automatically installed to their latest versions when running the tool.

Why This Tool?

If you are fed up with the tedious process of setting up a new Django project, then you've come to the right place!

This tool eliminates all the boring minor changes needed to the settings.py file and runs the preliminary setup commands for activating a Django project, such as projectstart, startapp, migrate, and createsuperuser.

The tool does the following (not necessarily in this order!):

  • Creates a virtual environment in the project folder
  • Accesses it, updates pip and installs the required packages
  • Generates a requirements.txt file
  • Creates a .env file with an updated DJANGO_SECRET_KEY ready for production using the get_random_secret_key() utility function
  • Updates the config/settings.py file to include all the necessary required changes, such as:
    • Replacing values to access the .env
    • Updating INSTALLED_APPS
    • Updating MIDDLEWARE
    • Updating the TEMPLATES DIRS
    • Updating the STATICFILES section
    • Adding the django-compressor settings
  • Creates a firstapp
  • Updates config/urls.py to include django-browser-reload and firstapp
  • Creates a _base.html and an index.html file in firstapp/templates/firstapp
  • Creates a Flowbite navbar in firstapp/templates/firstapp/components
  • Creates a superuser based on default values in the setup.py file
  • Performs initial database migration

Customisation

There are a few ways to add custom elements to the tool.

Firstly, you can edit the constant variables in the config.py file. These include:

  • The projectapp directory name
  • The firstapp directory name
  • The STATIC_URL and STATIC_ROOT_DIR
  • The createsuperuser admin details
  • The PIP packages to install
  • Various items to add to the settings.py file, such as items in the INSTALLED_APPS and MIDDLEWARE sections

Secondly, you can add custom files to the setup_assets folder. These are divided into three folders:

  • root - for root files in the main project directory
  • static - for static items such as css, js, and img files
  • templates - for template files in your project

Note: template files follow the standard convention required by Django to work correctly. For example, the ones in firstapp follow the convention: templates/firstapp/... where firstapp is automatically updated to the FIRSTAPP_DIR name in config.py.

Dependencies

Note: The install requires NodeJS, NPM, and Python to be installed on your local machine.

Creation

  1. To get started, clone the repository, enter the folder and run setup.py with a name argument to create a new project inside the django_project_quickstart_tool directory:
git clone https://github.com/Achronus/django_project_quickstart_tool.git
cd django_project_quickstart_tool
python setup.py my_project

OR create a project directory outside of the django_project_quickstart_tool inside its parent directory using the --outside flag:

python setup.py my_project --outside

Replacing A Project With the Same Name

Looking to replace an existing project with the same name? Use the --force flag to delete the old project and create a new one!

python setup.py my_project --outside --force

And That's It!

Everything is setup with a blank template ready to start building a project from scratch.

Simply, enter the new project folder:

# If using the --outside flag
cd ../my_project
# Otherwise
cd my_project

Run the Django server in one terminal:

python manage.py runserver

And watch TailwindCSS in another (remember to be in the project folder!):

npm run dev

Folder Structure

The newly created project should look similar to the following:

project_name
└── config
|   └── __init__.py
|   └── asgi.py
|   └── settings.py
|   └── urls.py
|   └── wsgi.py
└── core
|   └── migrations
|   |   └── ...
|   └── static
|   |   └── imgs
|   |   |   └── avatar.svg
|   |   └── css
|   |   |   └── input.css
|   |   |   └── output.css
|   |   └── js
|   |   |   └── alpine.min.js
|   |   |   └── flowbite.min.js
|   |   |   └── htmx.min.js
|   |   |   └── theme-toggle.js
|   └── templates
|   |   └── core
|   |   |   └── components
|   |   |   |   └── mobile-nav.html
|   |   |   |   └── navbar.html
|   |   |   └── _base.html
|   |   |   └── index.html
|   └── __init__.py
|   └── admin.py
|   └── apps.py
|   └── models.py
|   └── tests.py
|   └── urls.py
|   └── views.py
└── node_modules
|   └── ...
└── venv
|   └── ...
└── .env
└── .gitignore
└── db.sqlite3
└── manage.py
└── package.json
└── package-lock.json
└── requirements.txt
└── tailwind.config.js

Noteworthy Files and Folders

  • config/ - core settings created by using django-admin startproject
  • core/ - a standard app created using python manage.py startapp that stores the primary static files and templates for the project
  • core/templates/core/index.html - application homepage