inertiajs / inertia-django

The Django adapter for Inertia.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't get shared_data to work

Fidel-C opened this issue · comments

The exact example in the docs just doesn't work in my case, or was anything omitted in the docs? The idea of having to pass the same data to all views, which is now the only alternative, doesn't seem quite nice.

Did you add your middleware in settings MIDDLEWARE?

settings.py

MIDDLEWARE = [
    ...
    "inertia.middleware.InertiaMiddleware",
    "core.middleware.inertia_share",
]

Thanks, will see if this works. Because I'm just seeing the second middleware ("core.middleware.inertia_share") for the first time.

And I noticed that after form request using useForm()
from the inertia vue the response comes like a modal containing the json as strings instead of pure json responses. Any fix for that?

"core.middleware.inertia_share" throws errors

"core.middleware.inertia_share" throws errors

"core" is your django app (usually you have at least one)
"middleware" is your middleware python module (middleware.py)
"inertia_share" is your middleware function (located inside middleware.py)

https://docs.djangoproject.com/en/4.2/topics/http/middleware/#activating-middleware

Hey @Fidel-C, I don't know of any issues here and this is working fine in my apps so I suspect it's something on your end that isn't clear in the docs. Could you provide some more information about your setup?

Thanks @dr3tt for the debugging help!