inertiajs / inertia-django

The Django adapter for Inertia.js
MIT License
326 stars 32 forks source link

Can't get shared_data to work #29

Open Fidel-C opened 1 year ago

Fidel-C commented 1 year ago

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.

dr3tt commented 1 year ago

Did you add your middleware in settings MIDDLEWARE?

settings.py

MIDDLEWARE = [
    ...
    "inertia.middleware.InertiaMiddleware",
    "core.middleware.inertia_share",
]
fidelesq commented 1 year ago

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

fidelesq commented 1 year ago

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?

fidelesq commented 1 year ago

"core.middleware.inertia_share" throws errors

dr3tt commented 1 year ago

"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

BrandonShar commented 1 year ago

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!