Comments (15)
@Goldziher I'm not home right now. Tomorrow I will make a github repo with whole Piccolo template and post the link here.
from litestar.
@Goldziher Here is a repo. Starlite changes are in app.py and endpoints.py and all other files are the same for all starter asgi templates. Take a look at the comments I left in the code. You can git clone repo better than fork because I will delete that repo.
from litestar.
Great, I'll check it in the evening.
from litestar.
I already added the admin function to route_handlers
before and get an error.
I am getting an internal server error after i created the user as per the documentation served from 127.0.0.1:8000, but i am running the DB in docker etc. and have no clue if im using this correctly. I did attach a debugger to this stuff, but I am not sure I want to really delve into this code to figure out why the fast api based admin is not working
No problem. There doesn't seem to be an easy way to mount Piccolo Admin, but it doesn't matter, I just wanted to give it a try. Thanks for your time and help. I will close this issue. Cheers.
from litestar.
Sure thing. Note- for my money this is mounted, there is an error being returned from it, but the cause of the error cannot be ascertain without debugging the code internally. The issue is no longer with the mount - its something else. @sinisaos
from litestar.
Hi, have you tried using the asgi
decorator?
from litestar.
@Goldziher Yes, I have already tried this without success, because the asgi decorator function must return the response (if response is not ok we get 500 error ImproperlyConfiguredException: Unable to serialize response content
) not the asgi app.
from litestar.
can you show me some code? how did you use it?
from litestar.
Ok, so looking at the code, you currently have this:
admin_app = create_admin(
tables=APP_CONFIG.table_classes,
# Required when running under HTTPS:
# allowed_hosts=['my_site.com']
)
@asgi(path="/admin")
async def admin(scope: Scope, receive: Receive, send: Send) -> None:
if scope["type"] == "http":
if scope["method"] == "GET":
response = Response({"hello": "world"}, status_code=HTTP_200_OK) ????
await response(scope=scope, receive=receive, send=send)
return
response = Response(
{"detail": "unsupported request"}, status_code=HTTP_400_BAD_REQUEST
)
await response(scope=scope, receive=receive, send=send)
# middleware for Piccolo Admin
class AdminMiddleware(MiddlewareProtocol):
def __init__(self, app: ASGIApp):
self.app = admin_app
async def __call__(
self, scope: Scope, receive: Receive, send: Send
) -> None:
if scope["type"] == "http":
request = Request(scope)
await self.app(scope, receive, send)
But I don't understand why you'd use the response app there - response is an ASGI app that returns http responses. What you want is something like this instead:
admin_app = create_admin(
tables=APP_CONFIG.table_classes,
# Required when running under HTTPS:
# allowed_hosts=['my_site.com']
)
@asgi(path="/admin")
async def admin(scope: Scope, receive: Receive, send: Send) -> None:
await admin_app(scope=scope, receive=receive, send=send)
I also don't see the point for the middleware - a middleware is basically a pipeline to either evaluate a request or modify it, what you want is to basically have an ASGI app mounted on a specific path.
from litestar.
@Goldziher I agree with you and thatβs why I asked the question here because I dont know how to make Piccolo Admin to work with Starlite.
@asgi(path="/admin")
async def admin(scope: Scope, receive: Receive, send: Send) -> None:
await admin_app(scope=scope, receive=receive, send=send)
This is not working (error 404 Not Found
).
from litestar.
I see. Is piccolo exposing an asgi app?
from litestar.
Here is Piccolo Admin docs about asgi.
In Starlette or BlackSheep we can easily mount Piccolo Admin like this.
app = Starlette()
app.mount(
"/admin/",
create_admin(
tables=APP_CONFIG.table_classes,
# Required when running under HTTPS:
# allowed_hosts=['my_site.com']
),
)
from litestar.
so, you get a 404 because you didn't add the admin function into the route handlers:
from piccolo.engine import engine_finder
from piccolo_admin.endpoints import create_admin
from starlette.types import Receive, Scope, Send
from home.endpoints import create_task, delete_task, home, tasks, update_task
from home.piccolo_app import APP_CONFIG
from starlite import (
OpenAPIConfig,
Starlite,
StaticFilesConfig,
TemplateConfig,
asgi,
)
from starlite.template.jinja import JinjaTemplateEngine
# Piccolo Admin asgi app
admin_app = create_admin(
tables=APP_CONFIG.table_classes,
# Required when running under HTTPS:
# allowed_hosts=['my_site.com']
)
# I don't know how to pass Piccolo Admin app to this route with asgi decorator
# because this function returns response and not asgi app and if response is not ok
# we get 500 error ImproperlyConfiguredException: Unable to serialize response content
@asgi(path="/admin")
async def admin(scope: Scope, receive: Receive, send: Send) -> None:
admin_app(scope=scope, receive=receive, send=send)
async def open_database_connection_pool():
try:
engine = engine_finder()
await engine.start_connection_pool()
except Exception:
print("Unable to connect to the database")
async def close_database_connection_pool():
try:
engine = engine_finder()
await engine.close_connection_pool()
except Exception:
print("Unable to connect to the database")
app = Starlite(
debug=True,
route_handlers=[admin, home, tasks, create_task, update_task, delete_task],
template_config=TemplateConfig(
directory="home/templates", engine=JinjaTemplateEngine
),
openapi_config=OpenAPIConfig(
title="Starlite API",
version="1.0.0",
),
static_files_config=[
StaticFilesConfig(directories=["static"], path="/static"),
],
on_startup=[open_database_connection_pool],
on_shutdown=[close_database_connection_pool],
)
from litestar.
I am getting an internal server error after i created the user as per the documentation served from 127.0.0.1:8000, but i am running the DB in docker etc. and have no clue if im using this correctly. I did attach a debugger to this stuff, but I am not sure I want to really delve into this code to figure out why the fast api based admin is not working π
from litestar.
@Goldziher Nevermind. It was just my little experiment and trying out a new framework.
from litestar.
Related Issues (20)
- Enhancement: Only generate example once when `Parameter(examples=[...])` is specified for path arg and its schema HOT 4
- Bug: Response examples are not generated even with `generate_examples=True` HOT 5
- Enhancement: Generate OpenAPI schema always in the same order HOT 16
- Enhancement: only expose the path in `ValidationException`s HOT 6
- Docs: Exceptions are not always JSON by default
- Bug: Logging middleware with structlog causes application to return HTTP 500 when request body is malformed HOT 4
- Enhancement: Add `ResponseSpec(examples=...)` HOT 4
- Bug: `null` type OpenAPI response generated for ResponseSpec(None) / 204 HOT 3
- Bug: Sync `after_exception` handler prints `NoneType: None` when logging stacktrace HOT 11
- Bug: Examples not appearing in OpenAPI request HOT 10
- Documentation Style Overhaul HOT 4
- Bug: Logger memory leak through threads HOT 3
- Bug: Exception handler leaks internal exceptions HOT 2
- Bug: declaring a RedisStore in the app triggers a 500 error in the 2nd set of parameters of a parametrized test HOT 13
- Request to Package litestar for Conda Distribution HOT 1
- Enhancement: Support "+json" suffixed media types per RFC 6839 HOT 4
- Bug: session middleware cookies always include segment number HOT 2
- Docs: Minor inconsistencies in description and example for "Applications" chapter HOT 3
- Enhancement: Session Middleware should create session id right away HOT 6
- Docs: Translate Them HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from litestar.