Here's a complete example, that includes table definitions, configuring a `database.Database`
instance, and a couple of endpoints that interact with the database.
-**.env**
-
-```ini
+```ini title=".env"
DATABASE_URL=sqlite:///test.db
```
-**app.py**
-
-```python
+```python title="app.py"
import contextlib
import databases
You should only raise `HTTPException` inside routing or endpoints.
Middleware classes should instead just return appropriate responses directly.
-You can use an `HTTPException` on a WebSocket endpoint in case it's raised before `websocket.accept()`.
-The connection is not upgraded to a WebSocket connection, and the proper HTTP response is returned.
+You can use an `HTTPException` on a WebSocket endpoint. In case it's raised before `websocket.accept()`
+the connection is not upgraded to a WebSocket connection, and the proper HTTP response is returned.
```python
from starlette.applications import Starlette
from starlette.requests import Request
from starlette.responses import Response
-
+
async def app(scope, receive, send):
assert scope['type'] == 'http'
request = Request(scope, receive)
```
!!! info
- As settled in [RFC-7578: 4.2](https://www.ietf.org/rfc/rfc7578.txt), form-data content part that contains file
+ As settled in [RFC-7578: 4.2](https://www.ietf.org/rfc/rfc7578.txt), form-data content part that contains file
assumed to have `name` and `filename` fields in `Content-Disposition` header: `Content-Disposition: form-data;
- name="user"; filename="somefile"`. Though `filename` field is optional according to RFC-7578, it helps
- Starlette to differentiate which data should be treated as file. If `filename` field was supplied, `UploadFile`
- object will be created to access underlying file, otherwise form-data part will be parsed and available as a raw
+ name="user"; filename="somefile"`. Though `filename` field is optional according to RFC-7578, it helps
+ Starlette to differentiate which data should be treated as file. If `filename` field was supplied, `UploadFile`
+ object will be created to access underlying file, otherwise form-data part will be parsed and available as a raw
string.
#### Application
merge_init_into_class: true
parameter_headings: true
show_signature_annotations: true
+ show_source: false
signature_crossrefs: true
import:
- url: https://docs.python.org/3/objects.inv