如何将烧瓶中的自定义变量发送到JS/HTML以渲染图像?
这是我的基本Python代码,将可变帐户名称发送到JavaScript上,该代码将呈现图像。
@app.route('/<username>', methods=['GET', 'POST'])
def user_profile_name(username):
# return f"welcome to profile page {username}"
my_friends = database.GET_FRIENDS(connection, username)
# print(send_string)
return render_template(f"user_profile.html", friends=my_friends, account_name=username)
这是我的html,应该使用该名称到达该文件
<div>{{account_name}}</div>
<div id="profile picture">
<h1>Profile Picture</h1>
<img src="{{url_for('static', filename='#UserData/{{account_name}}/profile/profile_pic.jpg')}}\" width='200' height='200' />
,如果我手动地将名称放在那里,它可以正常工作,有什么想法我如何将我的名字发送给我?
filename='#UserData/MY_NAME_HERE/profile/profile_pic.jpg')}}\" width='200' height='200'
谢谢你的时间
Here is my basic python code to send the variable account name over to the javascript which will render the image.
@app.route('/<username>', methods=['GET', 'POST'])
def user_profile_name(username):
# return f"welcome to profile page {username}"
my_friends = database.GET_FRIENDS(connection, username)
# print(send_string)
return render_template(f"user_profile.html", friends=my_friends, account_name=username)
Here is my HTML that should go to the file with that name
<div>{{account_name}}</div>
<div id="profile picture">
<h1>Profile Picture</h1>
<img src="{{url_for('static', filename='#UserData/{{account_name}}/profile/profile_pic.jpg')}}\" width='200' height='200' />
The image is there, and if I put the name in manually like so, it works, any idea how I can send my name over?
filename='#UserData/MY_NAME_HERE/profile/profile_pic.jpg')}}\" width='200' height='200'
thanks for your time
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
(还确定您是否要在 userdata 之前都想要该标签,以及骆驼盒和蛇盒的混合物?更好地使用dash案例吗?对于HTML)。
(Also, are you sure that you want that hashtag before UserData, and that mix of camel case and snake case? Better to use dash case for HTML. )