You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/building-projects/app_basics.md
+12-11Lines changed: 12 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -8,26 +8,27 @@ Every view project will have a `new_app` call. The simplest app looks like this:
8
8
from view import new_app
9
9
10
10
app = new_app()
11
+
app.run() # you'll learn about this later
11
12
```
12
13
13
14
`new_app` does a few important things:
14
15
15
-
- Loads the configuration, regardless of whether a config file exists.
16
-
- Sets the `App` address for use by `get_app` (more on that later).
17
-
- Loads finalization code for when the app closes.
16
+
-Loads the configuration, regardless of whether a config file exists.
17
+
-Sets the `App` address for use by `get_app` (more on that later).
18
+
-Loads finalization code for when the app closes.
18
19
19
20
While it's not required for every app, naming your app variable `app` is the proper convention for view, as that's the default variable searched for when using the `view serve` command, but more on that in a moment.
20
21
21
22
For now, just try to stick with naming your app file `app.py` and your `view.App` instance `app`.
22
23
23
-
::: view.app.App
24
+
::: view.app.new_app
24
25
25
26
## Launching Apps
26
27
27
28
Python libraries generally have two ways to run a web server:
28
29
29
-
- Running via the command line.
30
-
- Launching from Python itself (e.g. a `server.start(...)` function).
30
+
-Running via the command line.
31
+
-Launching from Python itself (e.g. a `server.start(...)` function).
31
32
32
33
Both have their benefits and downsides, so view.py supports both out of the box. `App` comes with its `run()` method, and the view CLI has the `view serve` command.
33
34
@@ -54,17 +55,17 @@ app.run()
54
55
print("you called the app with view serve") # this only runs when `view serve` is used
55
56
```
56
57
57
-
::: view.app.App.run
58
-
59
58
### Fancy Mode
60
59
61
60
View comes with something called "fancy mode", which is a fancy UI that shows when you run the app. If you would like to disable this, you can do one of two things:
62
61
63
-
- Disable the `fancy` setting in configuration.
64
-
- Pass `fancy=False` to `run()`.
62
+
-Disable the `fancy` setting in configuration.
63
+
-Pass `fancy=False` to `run()`.
65
64
66
65
You should disable it in the configuration if you completely despise fancy mode and don't want to use it at all, but if you only want to temporarily turn it off (for example, if you're a view.py developer and need to see proper output) then pass `fancy=False`.
67
66
67
+
::: view.app.App.run
68
+
68
69
## Getting the App
69
70
70
71
### Circular Imports
@@ -117,6 +118,6 @@ def index():
117
118
118
119
Every view.py project should contain a call to `new_app`. `new_app` does important things like loading your configuration, set's up finalization code, and letting the `App` instance be used by `get_app`.
119
120
120
-
Running an app can be done in two ways: programmatically via the `App.run` or through `view serve` command. However, every view.py app should contain an `App.run` to give the choice for running programmatically. By default, view.py has a fancy UI when running your app, which may be disabled via editing the config or passing `fancy=False` to `run()`.
121
+
Running an app can be done in two ways: programmatically via the `App.run` or through `view serve` command. However, every view.py app should contain an `App.run` to give the choice for running programmatically. By default, view.py has a fancy UI when running your app, which may be disabled via editing the config or passing `fancy=False` to `run()`.
121
122
122
123
Finally, circular imports occur when two Python modules try to import each other, which can happen a lot in view when getting the app from the app file (especially in manual routing). To fix it, View provides a `get_app` function to get you your `App` instance without an import.
0 commit comments