Create View
You can simply create a new view for an existing app by:
(venv) python3 -m manage create-view
It will prompt you for some required arguments.
As an example, here we will create a view called index.html an existing app called notes:
(venv) python3 -m manage create-view
App Name: notes
View Name: index
It will create the view for you in the /views/notes/
directory.
Note that you shouldn't provide the .html
for your view. Only the view name is enough!
Valid characters for the view name are: a-z
, -
, _
Templating Inheritance
As you may have noticed that layout.html
already created for you.
Indeed, this is a blueprint created by the create-app
command.
This view file is like a class (blueprint) that all other views can inherit.
If you open the index.html
file you will see that the framework have done the templating inheritance and some other tasks for you.
You can now add your HTML, CSS, and JavaScript codes and make the view what you want.
For instance, the created index
view for the notes
app from the past chapter loos like this:
Aurora uses Jinja2 templating engine for rendering the view files.
Using Views
You can use a view inside a controller using the View
class of Aurora framework:
You don't have to hard code your view to add the app name, the framework recognizes the app name for your view. However, you can do it explicitly:
You can also explicitly set the status code:
200
is the default status code for the view.
For whatever reason, if you want to return other app views, you can do it like:
Delete View
You can simply delete an existing view for an existing app by:
(venv) python3 -m manage delete-view
It prompts you for App Name and View Name. After confirmation of the data loss, it will delete your view permanently.