@ -67,7 +67,8 @@ If you go to `http://localhost:8000/questions` we should see the list of questio
Unfortunately, we'll get an error:
```text
django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured.
You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
```
This error happens because Django settings are not configured before importing the Django models.
@ -88,7 +89,7 @@ django.setup()
This will configure Django settings before importing the Django models.
## Step 7: Run the FastAPI application
## Step 7: Run the FastAPI application (again)
Now you can run the FastAPI application:
@ -97,3 +98,28 @@ fastapi dev main.py
```
And now if we go to `http://localhost:8000/questions` we should see a list of questions! 🎉
## Using the ORM in async routes
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: