def addProductType(): # form : product_id, bar_code form = request.form.to_dict() print('form', form) # 上传图片 file = request.files['file'] if file is not None: # 储存图片获取数据 data = Img.save_one(file, form) print('upload data', data) if data['src'] is not None and base_url not in data['src']: data['src'] = base_url + '/' + data['src'] form['cover'] = data['src'] if data is not None: r = Res.success(data) else: r = Res.fail({}, msg='图片已存在') print('新图片', form) product = Product.add(form) if type(product) is str: r = Res.fail(msg=product) else: all = Product.all() print('all', all) r = Res.success(all) return make_response(jsonify(r))
def seller_index(seller): T = {'sellername':seller} helpers.template.get_user(T=T, path=request.path) products = [] pp = Product.all().fetch(limit=10) host = "http://localhost:5000/" for p in pp: product = {} product['seller'] = p.seller product['code'] = p.code product['title'] = p.title product['desc'] = p.desc product['price'] = u"%d 円" % p.price if p.image1: path = get_image_path(p.seller, p.code, 1, '120', '120', p.image1) product['imgurl'] = '%s%s' % (host, path) else: product['imgurl'] = 'http://placehold.it/120x120' products.append(product) T["products"] = products return render_template('seller_index.html', T=T)
def get(self): path = os.path.join(os.path.dirname(__file__), '../views/products/index.html') template_values = { 'name': self.__class__.__name__, 'products': Product.all(), } self.response.out.write(template.render(path, template_values))
def index(): u = current_user() ps = Product.all() return render_template('index.html', u=u, ps=ps)
def index(): # ms = Product.all() u = current_user() # print('user:'******'index.html', u=u, ps=ps)