is Django.Shortcuts import Render is high memory consumption for the system?

i want to make a html view with some data from the DB. i want to use the render function from the views.py and show it in the html. the code will look like this as example.
views.py

def progress_proyek_detail(request):
    bobot_per_week_data = BobotperWeek.objects.all()
    progress_data = ProgressProyek.objects.all()
    
    data = {
        'progress_data': progress_data,
        'bobot_per_week_data': bobot_per_week_data,
    }
    return render(request, 'progress_proyek_detail.html', data)

and for the html it will be like this

<!-- progress_proyek_detail.html -->

<!DOCTYPE html>
<html>
<head>
    <title>Progress Proyek Detail</title>
</head>
<body>
    <h1>Progress Proyek Data</h1>
    <table border="1">
        <thead>
            <tr>
                <th>Nomor</th>
                <th>Pekerjaan</th>
                <th>Bobot (%)</th>
                {% for bobot_per_week in bobot_per_week_data %}
                    <th>{{ bobot_per_week.tanggal }}</th>
                {% endfor %}
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>1</td>
                <td>Pekerjaan Persiapan</td>
                <td>{{ progress_data.0.bobot_pekerjaan_persiapan }}</td>
            </tr>
            <tr>
                <td>2</td>
                <td>Pekerjaan Galian Tanah</td>
                <td>{{ progress_data.0.bobot_pekerjaan_galian_tanah }}</td>
            </tr>
            <tr>
                <td>3</td>
                <td>Pekerjaan Fondasi</td>
                <td>{{ progress_data.0.bobot_pekerjaan_fondasi }}</td>
            </tr>
            <tr>
                <td>4</td>
                <td>Pekerjaan Cor Beton Pile Cap</td>
                <td>{{ progress_data.0.bobot_pekerjaan_cor_beton_pile_cap }}</td>
            </tr>
            <tr>
                <td>5</td>
                <td>Pekerjaan Cor Beton Slug</td>
                <td>{{ progress_data.0.bobot_pekerjaan_cor_beton_slug }}</td>
            </tr>
            <tr>
                <td>6</td>
                <td>Pekerjaan Pelat Beton Lantai</td>
                <td>{{ progress_data.0.bobot_pekerjaan_pelat_beton_lantai }}</td>
            </tr>
            <tr>
                <td>7</td>
                <td>Pekerjaan Pelat Bawah Retaining Wall</td>
                <td>{{ progress_data.0.bobot_pekerjaan_pelat_bawah }}</td>
            </tr>
            <tr>
                <td>8</td>
                <td>Pekerjaan Dinding</td>
                <td>{{ progress_data.0.bobot_pekerjaan_dinding }}</td>
            </tr>
            <tr>
                <td>9</td>
                <td>Pekerjaan Konstruksi Baja</td>
                <td>{{ progress_data.0.bobot_pekerjaan_konstruksi_baja }}</td>
            </tr>
            <tr>
                <td>10</td>
                <td>Pekerjaan Penutup Atap dan Lain-lain</td>
                <td>{{ progress_data.0.bobot_pekerjaan_penutup }}</td>
            </tr>
            <tr>
                <td colspan="3">BOBOT RENCANA</td>
            </tr>
            <tr>
                <td colspan="3">KUMULATIF BOBOT RENCANA</td>
            </tr>
            <tr>
                <td colspan="3">BOBOT AKTUAL REALISASI</td>
            </tr>
            <tr>
                <td colspan="3">KUMULATIF BOBOT AKTUAL REALISASI</td>
            </tr>
            <tr>
                <td colspan="3">NILAI DEVIASI</td>
            </tr>
        </tbody>
    </table>
</body>
</html>

is it a good choice to use? i will add some more data fetching later in this views.py

Thank you for fencing your code, but you need to use the backtick - ` character instead of the apostrophe - '. (That’s ok, I’ve taken the liberty of fixing it for you.)

1 Like

I’m not sure I understand what your question is here.

Is this working for you? If not, please describe what the problem is.

If it is working for you, then why do you think there might be a problem?

so far this is working, so the quesstion is, is using render efficient for the work of the system? because i will put a lot of data to the dictionary.

data = {
        'progress_data': progress_data,
        'bobot_per_week_data': bobot_per_week_data,
    }

I got a suggestion to use a JSON response sent from the view, then the HTML will read that JSON. Which one is better? Using return JSON or return render?

This would be an architectural decision, not strictly a technical one.

If you return JSON, then the browser is responsible for converting the received data into HTML. So you need to make the decision as to where you want the work to be performed.

If you either remove excess spaces from the returned HTML or gzip the response, you’ll find that the effective size of the response is pretty comparable either way.

Whether this is really an issue is going to depend upon just how much data you’re talking about returning.

But in the general case, this isn’t something you should worry about unless you have some specific information that indicates a problem will exist.

1 Like

okay thanks Ken, based on what i read from your suggestion, for now i will use the render method, as that is the most familiar one to me. thank you so much