Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jinja2.exceptions.TemplateNotFound: fastapi_aad_auth.ui:base.html #89

Closed
ada0l opened this issue Mar 30, 2022 · 2 comments
Closed

jinja2.exceptions.TemplateNotFound: fastapi_aad_auth.ui:base.html #89

ada0l opened this issue Mar 30, 2022 · 2 comments

Comments

@ada0l
Copy link

ada0l commented Mar 30, 2022

Hello, i try use your library, but i get some problems

I wrote

import uvicorn
from fastapi import FastAPI, Request, Response, Depends
from starlette.middleware.sessions import SessionMiddleware
import os
from fastapi_sqlalchemy import DBSessionMiddleware
from fastapi_sqlalchemy import db
from models import User as ModelUser
from schema import User as SchemaUser
from dotenv import load_dotenv

from fastapi_aad_auth import AuthenticationState, Config, auth, Authenticator
from fastapi_aad_auth.providers.aad import AADConfig

auth_provider = auth.AADAuth()

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
load_dotenv(os.path.join(BASE_DIR, ".env"))

app = FastAPI()

auth_provider.configure_app(app)
app.add_middleware(DBSessionMiddleware, db_url=os.environ["DATABASE_URL"])
app.add_middleware(SessionMiddleware, secret_key="example")

@app.post("/user/", response_model=SchemaUser)
def create_user(user: SchemaUser):
    db_user = ModelUser(
        first_name=user.first_name, last_name=user.last_name, age=user.age
    )
    db.session.add(db_user)
    db.session.commit()
    return db_user

@app.get("/")
def index(auth_state: AuthenticationState = Depends(auth_provider.auth_backend.requires_auth(allow_session=True))):
    print(auth_state)
    return {'hello': 'world'}


if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=8000)

But when i try to load 127.0.0.1:8000/docs, i get an error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\andrey\.virtualenvs\backend-9dmwlUHU\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 366, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "C:\Users\andrey\.virtualenvs\backend-9dmwlUHU\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 75, in __call__
    return await self.app(scope, receive, send)
  File "C:\Users\andrey\.virtualenvs\backend-9dmwlUHU\lib\site-packages\fastapi\applications.py", line 261, in __call__
    await super().__call__(scope, receive, send)
  File "C:\Users\andrey\.virtualenvs\backend-9dmwlUHU\lib\site-packages\starlette\applications.py", line 112, in __call__
    await self.middleware_stack(scope, receive, send)
  File "C:\Users\andrey\.virtualenvs\backend-9dmwlUHU\lib\site-packages\starlette\middleware\errors.py", line 181, in __call__
    raise exc
  File "C:\Users\andrey\.virtualenvs\backend-9dmwlUHU\lib\site-packages\starlette\middleware\errors.py", line 159, in __call__
    await self.app(scope, receive, _send)
  File "C:\Users\andrey\.virtualenvs\backend-9dmwlUHU\lib\site-packages\starlette\middleware\base.py", line 63, in __call__
    response = await self.dispatch_func(request, call_next)
  File "C:\Users\andrey\.virtualenvs\backend-9dmwlUHU\lib\site-packages\fastapi_sqlalchemy\middleware.py", line 44, in dispatch
    response = await call_next(request)
  File "C:\Users\andrey\.virtualenvs\backend-9dmwlUHU\lib\site-packages\starlette\middleware\base.py", line 44, in call_next
    raise app_exc
  File "C:\Users\andrey\.virtualenvs\backend-9dmwlUHU\lib\site-packages\starlette\middleware\base.py", line 34, in coro
    await self.app(scope, request.receive, send_stream.send)
  File "C:\Users\andrey\.virtualenvs\backend-9dmwlUHU\lib\site-packages\starlette\middleware\sessions.py", line 77, in __call__
    await self.app(scope, receive, send_wrapper)
  File "C:\Users\andrey\.virtualenvs\backend-9dmwlUHU\lib\site-packages\starlette\middleware\authentication.py", line 48, in __call__
    await self.app(scope, receive, send)
  File "C:\Users\andrey\.virtualenvs\backend-9dmwlUHU\lib\site-packages\starlette\exceptions.py", line 82, in __call__
    raise exc
  File "C:\Users\andrey\.virtualenvs\backend-9dmwlUHU\lib\site-packages\starlette\exceptions.py", line 71, in __call__
    await self.app(scope, receive, sender)
  File "C:\Users\andrey\.virtualenvs\backend-9dmwlUHU\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 21, in __call__
    raise e
  File "C:\Users\andrey\.virtualenvs\backend-9dmwlUHU\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "C:\Users\andrey\.virtualenvs\backend-9dmwlUHU\lib\site-packages\starlette\routing.py", line 656, in __call__
    await route.handle(scope, receive, send)
  File "C:\Users\andrey\.virtualenvs\backend-9dmwlUHU\lib\site-packages\starlette\routing.py", line 259, in handle
    await self.app(scope, receive, send)
  File "C:\Users\andrey\.virtualenvs\backend-9dmwlUHU\lib\site-packages\starlette\routing.py", line 61, in app
    response = await func(request)
  File "C:\Users\andrey\.virtualenvs\backend-9dmwlUHU\lib\site-packages\fastapi_aad_auth\ui\__init__.py", line 123, in login
    return self._login(request)
  File "C:\Users\andrey\.virtualenvs\backend-9dmwlUHU\lib\site-packages\fastapi_aad_auth\ui\__init__.py", line 64, in _login
    return self.login_templates.TemplateResponse(self.login_template_path.name, context)  # type: ignore
  File "C:\Users\andrey\.virtualenvs\backend-9dmwlUHU\lib\site-packages\starlette\templating.py", line 90, in TemplateResponse
    return _TemplateResponse(
  File "C:\Users\andrey\.virtualenvs\backend-9dmwlUHU\lib\site-packages\starlette\templating.py", line 34, in __init__
    content = template.render(context)
  File "C:\Users\andrey\.virtualenvs\backend-9dmwlUHU\lib\site-packages\jinja2\environment.py", line 1291, in render
    self.environment.handle_exception()
  File "C:\Users\andrey\.virtualenvs\backend-9dmwlUHU\lib\site-packages\jinja2\environment.py", line 926, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "C:\Users\andrey\.virtualenvs\backend-9dmwlUHU\lib\site-packages\fastapi_aad_auth\ui\login.html", line 1, in top-level template code
    {% extends "fastapi_aad_auth.ui:base.html" %}
  File "C:\Users\andrey\.virtualenvs\backend-9dmwlUHU\lib\site-packages\jinja2\loaders.py", line 218, in get_source
    raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: fastapi_aad_auth.ui:base.html```
@djpugh
Copy link
Owner

djpugh commented Apr 17, 2022

Hi @ada0l - think this is the same a #72 - fixed in #75 and releasing soon

@djpugh djpugh closed this as completed Apr 17, 2022
@djpugh
Copy link
Owner

djpugh commented Apr 17, 2022

Released 0.1.22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants