python/django/vs code

62 views
Skip to first unread message

Mee “MeeGrp” Grp

unread,
Jun 5, 2024, 3:40:02 AMJun 5
to Django users
I have two html files 1. view_sales.html  2. total_sales.html

I want to display output of total_sales.html within  view_sales.html just below 
view_sales.html output

Your help would be highly appreciated !!!!!!!!


Web dev

unread,
Jun 5, 2024, 4:18:46 AMJun 5
to django...@googlegroups.com
Hi, I guess your trouble.
Let me try.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/30b6b324-22b2-44f1-b2dd-b0b034ac2f61n%40googlegroups.com.

Nagaraja

unread,
Jun 5, 2024, 10:54:46 PMJun 5
to django...@googlegroups.com
try below method
<body>
    {% block content %}
    {% endblock content %}
</body>

Bhagyashri Phalake

unread,
Jun 6, 2024, 12:43:46 PMJun 6
to Django users

  Calculate Total Sales in View

from django.shortcuts import render
from .models import Sale

def sales_report(request):
    sales = Sale.objects.all()
    total_sales = sales.aggregate(total=models.Sum('total_price'))['total']
    return render(request, 'sales_report.html', {'sales': sales, 'total_sales': total_sales})


Calculate Total Sales in View:

  from flask import Flask, render_template
from models import db, Sale

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///sales.db'
db.init_app(app)

@app.route('/sales_report')
def sales_report():
    sales = Sale.query.all()
    total_sales = sum(sale.total_price for sale in sales)
    return render_template('sales_report.html', sales=sales, total_sales=total_sales)

if __name__ == '__main__':
    app.run(debug=True)


Sales
------------------------------------------------------------
| Product   | Date       | Amount | Quantity Sold | Total Price |
------------------------------------------------------------
| Product A | 2024-06-01 | 100.00 | 2             | 200.00      |
| Product B | 2024-06-02 | 150.00 | 1             | 150.00      |
| Product A | 2024-06-03 | 100.00 | 3             | 300.00      |
------------------------------------------------------------
Total Sales: 650.00
Reply all
Reply to author
Forward
0 new messages