DFormKit is a Python library designed to help Django developers dynamically generate forms, manage views, and streamline template creation based on Django models.
This command-line wizard lets you dynamically generate forms, templates, views, and URL patterns for your Django models straight from your Terminal. It works seamlessly on Windows, Mac, and Linux, so you can use it on any platform.
While other tools make you wade through a swamp of settings and configurations, DFormKit keeps it simple. Just specify your app and model, and voilà! It’ll take you on a smooth ride to creating dynamic forms, no complex options needed—just fun coding! 🔥
- Dynamic Form Generation: Automatically generate forms from Django models.
- Template Creation: Create HTML templates for forms.
- View Integration: Add view functions and URL patterns dynamically.
- Customizable Templates: Supports integrating styling frameworks like Tailwind CSS.
-
Install the library using
pip:pip install dformkit
-
Add
'dformkit'toINSTALLED_APPSin your Django project'ssettings.pyfile:INSTALLED_APPS = [ ..., 'dformkit', ]
- image showing the addition of
'dformkit'toINSTALLED_APPSinsettings.py.
- image showing the addition of
Stay in the loop with the latest features on GitHub! To upgrade your DFormKit tool, simply run:
pip install --upgrade dformkitThen you’re all set to keep generating dynamic forms from your Terminal! 🥳
Getting started with DFormKit is a piece of cake! Just use the following command style:
python manage.py dformkit myapp PersonNote:
- Replace
myappwith your Django app name. - Replace
Personwith your model name.
If you don’t specify additional options, it’ll generate a dynamic form for the model and save it in forms.py. Easy-peasy!
| Argument | Description |
|---|---|
app |
The name of your Django app. This argument is [Required]. |
model |
The name of your Django model. This argument is [Required]. |
| Option | Description |
|---|---|
-page or --p |
Generate an HTML template for the form. |
-view or --v |
Add a view function to views.py and a URL pattern to urls.py. |
--pv or --vp |
Combine all options: generate the form, template, view, and URL pattern. |
python manage.py dformkit myapp Person- What it does: Generates a dynamic form for the
Personmodel in themyappapplication. - Output: The form is saved in
forms.py.
python manage.py dformkit myapp Person -pageor
python manage.py dformkit myapp Person --p-
What it does: Generates the form and an HTML template for it.
-
Output: The form is saved in
forms.py, and the template is saved in thetemplatesfolder. -
This is the code generated with this command in templates/[formname]_form.html
python manage.py dformkit myapp Person -viewor
python manage.py dformkit myapp Person --v- What it does: Generates the form, adds a view function to
views.py, and adds a URL pattern tourls.py. - Output: The form, view, and URL pattern are created.
python manage.py dformkit myapp Person --pvor
python manage.py dformkit myapp Person --vp-
What it does: Combines all the above steps into one command.
-
Output: The form, template, view, and URL pattern are generated.
-
this is the new form code in forms.py when use this command
You can use named arguments for more flexibility. For example:
python manage.py dformkit -app=myapp -model=Person -viewor
python manage.py dformkit -app=myapp -model=Person --pv- What it does: Works the same as positional arguments but provides a more explicit way to specify the app and model.
If the form already exists in forms.py, the library will warn you before overwriting it. You can choose to proceed or skip.
The generated templates are fully customizable. You can integrate styling frameworks like Tailwind CSS or Bootstrap by modifying the generated HTML files.
You can run unit tests using pytest:
pytestWe welcome contributions! Follow these steps:
- Fork the repository.
- Create a new branch for your feature or fix.
- Write tests if applicable.
- Submit a Pull Request with details about your changes.
- If the form already exists, the library will warn you before overwriting it. You can choose to proceed or skip.
- Yes, the generated templates are fully customizable. You can integrate styling frameworks like Tailwind CSS or Bootstrap.
- Validation is automatically handled based on the constraints defined in your Django model (e.g.,
max_length,null,blank, etc.).
DFormKit simplifies the process of generating forms, templates, views, and URL patterns in Django. By following the steps above, you can quickly set up dynamic forms for your models and streamline your development workflow.
This project is licensed under the MIT License.




