我正在使用Flask-Python并创建一个我想要做一段时间的传输应用程序。我遇到了标准文件上传的特定功能问题。我想要做的是尝试根据特定模型从我的图像文件夹动态渲染图像,但我似乎在尝试字符串插值时遇到问题。
def createuser(request):
file = request.files['aadharimage']
if file.filename == None:
flash('No selected file')
return redirect(request.url)
filename=''
if file:
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
users= Enduser(name=request.form["name"],fathername=request.form['fathername'],password=request.form["password"], aadhar_image=filename,email=request.form["email"],address=request.form["address"],type=request.form["type"],location_id=request.form["location_id"],mobile=request.form['mobile'],usertype=request.form['usertype'],lastlogin=request.form['lastlogin'],companyname=request.form['companyname'])
sqlsession.add(users)
sqlsession .commit()
@app.route ('/page/newuser')
def pagenewuser():
if session['username']:
return render_template("newuser.html", user session['username'],Locations=getlocation().all())
else:
flash('Please Login first!!')
return main()
@app.route('/page/edituser')
def pageedituser():
if session['username']:
users = getusers()
if users.first()== None:
return render_template("empty.html", user=session['username'])
else:
return render_template("edituser.html", user=session['username'], endusers=users.all() )
jinja2模板代码
<td>{{Values.id}}</td>
<td>{{Values.name}}</td>
<td>{{Values.fathername}}</td>
<td><img src="{{url_for('static',filename='assets/images/{{Values.aadhar_image}}')}}" alt="sample" width="25" height="24"/></td>
这里{{Values.aadharimage}}无效。你可以解决我的问题