Official solution
SimpleURL parameters se numbers lo, calculate karke return/render.
@app.route('/sum/<int:a>/<int:b>')
def add(a, b):
return f'Hello, sum is {a+b}'
Product: a*b. Square: n*n. Even/odd: 'even' if n%2==0 else 'odd'.
Form se: request.form.get('a', type=int). Background color even/odd:
color = 'green' if n%2==0 else 'red'
return render_template('page.html', color=color)
CSS: body { background: {{ color }}; }
Patternfilter query → template/JSON. Examiner jo entity bole us class ka naam use karo.
@app.route('/admin/blacklisted')
def blacklisted():
rows = User.query.filter_by(is_blacklisted=True).all()
return render_template('list.html', rows=rows)
JSON: return jsonify([{'id': r.id, 'name': r.name} for r in rows])
ID se: User.query.get_or_404(id)
Do filters: .filter(Drive.approved==False, Drive.title=='Data Scientist')
Join example: students jinhone blacklisted company ke drive pe apply kiya — join Application-Drive-Company.
PUT@app.route('/x/<int:id>', methods=['PUT']) + request.get_json()
url param display: @app.route('/show/<int:id>') return render_template('show.html', id=id)
Form → next page: POST values render_template('out.html', **request.form)
Count: return str(User.query.filter_by(is_blacklisted=True).count())