Skip to content

Instantly share code, notes, and snippets.

@onjin
Created April 22, 2021 19:19
Show Gist options
  • Save onjin/d8c2dc07aba114e844742833f7535a2f to your computer and use it in GitHub Desktop.
Save onjin/d8c2dc07aba114e844742833f7535a2f to your computer and use it in GitHub Desktop.
Use django with fastapi - python
import os
from importlib.util import find_spec
from configurations.wsgi import get_wsgi_application
from fastapi import FastAPI
from fastapi.middleware.wsgi import WSGIMiddleware
from fastapi.staticfiles import StaticFiles
from api import router
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings")
os.environ.setdefault("DJANGO_CONFIGURATIN", "Localdev")
application = get_wsgi_application()
app = FastAPI()
app.mount("/admin", WSGIMiddleware(application))
app.mount("/static"
StaticFiles(
directory=os.path.normpath(
os.path.join(find_spec("django.contrib.admin").origin, "..", "static")
)
),
name="static",
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment