Part 3: View¶
Writing the URLs¶
For a user to visit our app in FreedomBox, we need to provide a URL. When the
user visits this URL, a view is executed and a page is displayed. In urls.py
write the following:
from django.urls import re_path
from .views import TransmissionAppView
urlpatterns = [
re_path(r'^apps/transmission/$', TransmissionAppView.as_view(), name='index'),
]
This routes the /apps/transmission/
URL to a view called
TransmissionAppView
defined in plinth/modules/transmission/views.py
.
This is no different than how routing URLs is done in Django. See Django
URL dispatcher for more information.
Writing a view¶
We have a URL pointing to our view. We have also added a menu item in the apps
section of the web interface that points to our view. We now need to create a
view to show the app page for our app. In views.py
, let us add a view.
from plinth import views
from plinth.modules import transmission
class TransmissionAppView(views.AppView):
"""Serve configuration page."""
app_id = 'transmission'
The base view AppView
takes care of a lot of details for
us. First, it shows basic information about the app like name, description,
desktop/mobiles clients for the service (described later), link to the manual
page (described later), link to diagnostics button, etc. Then it shows the
status of the app whether it is running and can also present a form for
configuration. It also presents a way to enable/disable the app.