Welcome to the quick setup tool for creating a Django
project with the following stack:
-
TailwindCSS and Flowbite
-
Django Browser Reload - for automatic page reloading during development
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.
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 updatedDJANGO_SECRET_KEY
ready for production using theget_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
- Replacing values to access the
- Creates a
firstapp
- Updates
config/urls.py
to includedjango-browser-reload
andfirstapp
- Creates a
_base.html
and anindex.html
file infirstapp/templates/firstapp
- Creates a
Flowbite
navbar infirstapp/templates/firstapp/components
- Creates a
superuser
based on default values in thesetup.py
file - Performs initial database
migration
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
andSTATIC_ROOT_DIR
- The
createsuperuser
admin details - The
PIP
packages to install - Various items to add to the
settings.py
file, such as items in theINSTALLED_APPS
andMIDDLEWARE
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 directorystatic
- for static items such ascss
,js
, andimg
filestemplates
- 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
.
Note: The install requires NodeJS, NPM, and Python to be installed on your local machine.
- To get started, clone the repository, enter the folder and run
setup.py
with aname
argument to create a new project inside thedjango_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
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
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
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
config/
- core settings created by usingdjango-admin startproject
core/
- a standard app created usingpython manage.py startapp
that stores the primary static files and templates for the projectcore/templates/core/index.html
- application homepage