Browse Source

formatting of code sections

pull/11782/head
svlandeg 11 months ago
parent
commit
0daa2a6413
  1. 30
      docs/en/docs/advanced/django-orm.md

30
docs/en/docs/advanced/django-orm.md

@ -24,11 +24,11 @@ pip install fastapi
Let's create a basic FastAPI application in a new file called `main.py`: Let's create a basic FastAPI application in a new file called `main.py`:
=== "Python 3.8+" //// tab | Python 3.8+
```Python ```Python
{!> ../../../docs_src/django_orm/tutorial001.py[ln:5,13]!} {!> ../../../docs_src/django_orm/tutorial001.py[ln:5,13]!}
``` ```
In the next steps we'll import the `Question` model from Django, and create a FastAPI endpoint to list all questions. In the next steps we'll import the `Question` model from Django, and create a FastAPI endpoint to list all questions.
@ -36,11 +36,11 @@ In the next steps we'll import the `Question` model from Django, and create a Fa
In your `main.py` file, let's import the `Question` model and create a FastAPI endpoint to list all questions: In your `main.py` file, let's import the `Question` model and create a FastAPI endpoint to list all questions:
=== "Python 3.8+" //// tab | Python 3.8+
```Python ```Python
{!> ../../../docs_src/django_orm/tutorial001.py[ln:10,16-20]!} {!> ../../../docs_src/django_orm/tutorial001.py[ln:10,16-20]!}
``` ```
## Step 4: Run the FastAPI application ## Step 4: Run the FastAPI application
@ -67,11 +67,11 @@ To fix this error, we need to configure Django settings before importing the Dja
In the `main.py` add the following code **before** importing the Django models: In the `main.py` add the following code **before** importing the Django models:
=== "Python 3.8+" //// tab | Python 3.8+
```Python ```Python
{!> ../../../docs_src/django_orm/tutorial001.py[ln:1,7-10]!} {!> ../../../docs_src/django_orm/tutorial001.py[ln:1,7-10]!}
``` ```
Now, if you run the FastAPI application again, you should see the list of questions at `http://localhost:8000/questions`! 🎉 Now, if you run the FastAPI application again, you should see the list of questions at `http://localhost:8000/questions`! 🎉
@ -84,8 +84,8 @@ In this guide, we learned how to use Django's ORM with FastAPI. This can be extr
Django's support for async is currently limited, if you need to do run any query in an async route (or function), Django's support for async is currently limited, if you need to do run any query in an async route (or function),
you need to either use the async equivalent of the query or use `sync_to_async` from `asgiref.sync` to run the query: you need to either use the async equivalent of the query or use `sync_to_async` from `asgiref.sync` to run the query:
=== "Python 3.8+" //// tab | Python 3.8+
```Python ```Python
{!> ../../../docs_src/django_orm/tutorial001.py[ln:23-37]!} {!> ../../../docs_src/django_orm/tutorial001.py[ln:23-37]!}
``` ```

Loading…
Cancel
Save