Skip to content

Commit

Permalink
Add microdjango example
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinche committed Nov 2, 2023
1 parent fc9b27e commit 861097f
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,41 @@ run(app.run(__name__))
```
````

```{tab} Django
````{tab} Django
```python
from django.conf import settings
from django.core.handlers.wsgi import WSGIHandler
from django.core.management import execute_from_command_line
from uapi.django import App
app = App()
@app.get("/")
def hello() -> str:
return "hello world"
settings.configure(ALLOWED_HOSTS="*", ROOT_URLCONF=__name__)
urlpatterns = app.to_urlpatterns()
Unfortunately, Django is too complex to be able to spin up a development server quickly.
Please see the Django section for information on how to integrate a _uapi_ `App` into a Django site.
if __name__ == "__main__":
execute_from_command_line()
else: # new
application = WSGIHandler()
```
Then run the file using `python <filename> runserver`.
```{note}
This example uses code from the [µDjango](https://github.com/wsvincent/django-microframework) project.
```
````

````{tab} Aiohttp
Change the code to the following, and run it:
Expand Down

0 comments on commit 861097f

Please sign in to comment.