Python (使用Flask框架):yanziliangpin.com
python
from flask import Flask, render_template, request
app = Flask(name)
@app.route(‘/’)
def index():
# 假设你有一个商品列表
products = [{“name”: “Product1”, “price”: 100}, {“name”: “Product2”, “price”: 200}]
return render_template(‘index.html’, products=products)
if name == ‘main’:
app.run(debug=True)
对应的index.html可以是一个简单的商品列表展示。
JavaScript (Node.js 使用Express框架):
javascript
const express = require(‘express’);
const app = express();
const port = 3000;
app.get(‘/’, (req, res) => {
// 假设你有一个商品列表
let products = [{“name”: “Product1”, “price”: 100}, {“name”: “Product2”, “price”: 200}];
res.render(‘index’, { products: products });
});
app.listen(port, () => {
console.log(Server running at http://localhost:${port}
);
});
这里同样需要一个名为index的视图模板来展示商品。
PHP:
对于一个简单的商品列表展示,你可以创建一个index.php文件:
php
<?php // 假设你有一个商品数组 $products = array( array("name" => "Product1", "price" => 100), array("name" => "Product2", "price" => 200) ); ?>Product List
- <?php foreach($products as $product): ?>
- <?php echo $product['name']; ?> - $<?php echo $product['price']; ?>
- <?php endforeach; ?>
Python (使用Flask框架):
python
from flask import Flask, render_template, request
app = Flask(name)
@app.route(‘/’)
def index():
# 假设你有一个商品列表
products = [{“name”: “Product1”, “price”: 100}, {“name”: “Product2”, “price”: 200}]
return render_template(‘index.html’, products=products)
if name == ‘main’:
app.run(debug=True)
对应的index.html可以是一个简单的商品列表展示。
JavaScript (Node.js 使用Express框架):
javascript
const express = require(‘express’);
const app = express();
const port = 3000;
app.get(‘/’, (req, res) => {
// 假设你有一个商品列表
let products = [{“name”: “Product1”, “price”: 100}, {“name”: “Product2”, “price”: 200}];
res.render(‘index’, { products: products });
});
app.listen(port, () => {
console.log(Server running at http://localhost:${port}
);
});
这里同样需要一个名为index的视图模板来展示商品。
PHP:
对于一个简单的商品列表展示,你可以创建一个index.php文件:
php
<?php // 假设你有一个商品数组 $products = array( array("name" => "Product1", "price" => 100), array("name" => "Product2", "price" => 200) ); ?>Product List
- <?php foreach($products as $product): ?>
- <?php echo $product['name']; ?> - $<?php echo $product['price']; ?>
- <?php endforeach; ?>