So, you’ve got some web development experience and have built Django apps before. Remember the “Writing your first Django app” tutorial on the Django website? It’s a good start but often leaves you wanting more.
In this guide, we’ll walk you through building a basic Viewflow app that’s not just functional but also presentable to your customers. We’ll start with the basic structure, add BPMN and FSM workflows, customize forms and CRUD, and top it off with a reporting dashboard.
First, let’s set up a fresh virtual environment for the demo project. Open your terminal and run:
python3 -m venv .venv source .venv/bin/activate
Viewflow requires Python>=3.8 and Django>=4.0. Next, install the Viewflow open source package:
pip install django-viewflow
Or, if you have Viewflow PRO:
pip install django-viewflow-pro --extra-index-url
https://pypi.viewflow.io/<licence_id>/simple/
Now, scaffold a new Django project:
django-admin startproject demo .
Create an app:
./manage.py startapp helloworld
Your file structure should now look like this:
demo/
├── asgi.py
├── __init__.py
├── settings.py
├── urls.py
└── wsgi.py
helloworld
├── admin.py
├── apps.py
├── __init__.py
├── migrations
│ └── __init__.py
├── models.py
├── tests.py
└── views.py
manage.py
Open the demo/settings.py and add viewflow and helloworld into INSTALLED_APPS setting
INSTALLED_APPS = [
... 'viewflow', 'helloworld',
]
Let’s set up the basic structure for our site. Viewflow uses a Class-Based URL configuration called Viewset. Each viewset combines a set of views and builds a list of URL patterns.
Think of Viewset as the main building block of your website. You get a working solution out of the box, but you can also customize it as needed.
Viewflow comes with several pre-built Viewsets perfect for business applications. The Site viewset is the top-level one, and it can contain several Application viewsets. Each Application viewset can have nested viewsets of their own. To start, open demo/urls.py and add the following code:
from django.urls import path from django.contrib.auth.models import User
from viewflow.contrib.auth import AuthViewset from viewflow.urls import
Application, Site, ModelViewset
site = Site(title="ACME Corp", viewsets=[
Application(
title='Sample App', icon='people', app_name='sample', viewsets=[
ModelViewset(model=User),
]
),
])
urlpatterns = [
path('accounts/', AuthViewset(with_profile_view=False).urls), path('',
site.urls),
]
Here we set up a site with a single application and expose default CRUD for the built-in Django User model. We also use the default Viewflow AuthViewset to enable the login dialog.
Apply standard Django’s migrations to create an initial database structure
./manage.py migrate
Create an admin user for initial login
./manage.py createsuperuser
Run the server
./manage.py runserver
Visit http://127.0.0.1:8000 to see Viewflow in action!