@server_function — same-origin RPC
JavaScript calls Python, gets JSON back. No VDOM diff, no patches. Use when the page state shouldn't change but the browser needs a server-computed value.
@action
dj-form-pending
@server_function
dj-transition
ActivityMixin
WizardMixin
dj_suspense
defer()
DataTableMixin
dj-virtual
dj-viewport
UploadMixin
Try it
@server_functionClick to invoke calculate_total on the server. The result lands in #sf-output via JS — the page itself doesn't re-render.
// log in to enable the button
Server side
from djust import server_function
class CalculatorView(LiveView):
api_name = "scaffold.calculator" # browser slug for djust.call()
@server_function(description="Compute total from an item list")
def calculate_total(self, items: list, **kwargs) -> dict:
subtotal = sum(i['price'] * i['qty'] for i in items)
return {'subtotal': subtotal, 'tax': round(subtotal * 0.08, 2)}
Client side
// Client-side — no VDOM re-render, just a JSON round-trip
const result = await djust.call(
'scaffold.calculator', // view slug (api_name)
'calculate_total', // function name
{items: [{price: 9.99, qty: 2}, {price: 4.50, qty: 3}]}
);
console.log(result.subtotal, result.tax); // 33.48 2.68
See docs.djust.org/api/server-functions/ for the full API.