Parse Django - server side server side or client side?

While working on django app development, what is the best practice for rendering client-side model objects? Should models be handled using server side code, or is it better to leave templating / javascript on the client side?

Server side example:

for order in to_do_orders:
        orderDict[order.orderID] = Order.objects.get(pk=order.orderID.id)
        orderDict['customer'] = Customer.objects.get(pk=Order.objects.get(pk=order.orderID.id).customer.id)

      

vs client:

{% for order in orders %}
        {{ order.id }}</a></li>
        {{customer}}
    {% endfor %}

      

+3


source to share


2 answers


For Django, my understanding is this:

If the routine affects the display of data, place the logic in the template.

If the routine affects the display of data, put the logic in a function in the view.



If a routine affects how data is retrieved, consider using the Model Manager instead of the View function.

In your example, it is convenient to use order.id

in a template because you need to pass the container object to the template - the orders dictionary.

+2


source


What you call "Server" and "Client" are actually Python code and templates that are interpreted on the server.



I don't think it matters, except that readability and reusability are keys. For this purpose, the second option (using template functions) certainly looks the best. Though I'm pretty sure there are many exceptions.

-1


source







All Articles