图像未通过本地主机显示在HTTP web文件中



我正在使用flask和python为我的辅助项目制作一个小型网站。我插入了一些图像,当我打开html文件时,我可以看到这些图像存储在与html文件相同的目录中。但是,当我尝试运行脚本时,图像不会显示。

这是python scipt:

@app.route('/', methods=('GET', 'POST'))
def contact():
global final_filename
global real_post_response

form = UploadForm()
if form.validate_on_submit():

name = form["name"].data
email_address = form["email"].data
up_file = form.chat_file.data
filename = secure_filename(up_file.filename)
filename=filename.replace(".txt", "")
now_time=datetime.now()
filename=filename+"_"+now_time.strftime('%m_%d_%H_%M_%S')
filename=filename+".txt"

up_file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
add_erp_user_info(email_address,filename,name)
send_simple_email(name, email_address, filename)
final_filename=filename

print ("final_filename (in upload file) is ", final_filename)
real_post_response=True
print ("changing real post response to true")
return redirect(url_for('uploaded_file'))

return render_template('contact.html', form=form)

这是contact.html脚本:


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Project Bluetick: Relationship SMS-Analysis</title>
<link rel="stylesheet" type= "text/css" href= "{{url_for('static', filename='styles/contact.css') }}">
</head>


<h1>Project Bluetick: Are you texting your partner too much?</h1>
<h2> Let's use objective data to find out! </h2>
<h2> See the medium article <a href=https://medium.com/@luyilousia/improving-my-dating-life-one-text-analysis-at-a-time-a802cb8c2876>here</a> </h2>
<h2> Or if you prefer to <a href= https://breakinguppodcast.podbean.com/e/episode-31-project-bluetick-analysing-relationships-through-whatsapp-data/> listen </a> </h2>


<div class="formwrapper">
<h2 class="title">Upload your whatsapp chat history:</h2>
<form  method="POST" enctype="multipart/form-data" >

{{ form.hidden_tag() }}

{% if form.name.errors %}       
{% for error in form.name.errors %}
<div class="flash">{{ error }}</div>
{% endfor %}       
{% endif %}
{% if form.email.errors %}       
{% for error in form.email.errors %}
<div class="flash">{{ error }}</div>
{% endfor %}        
{% endif %}
{% if form.chat_file.errors %}      
{% for error in form.chat_file.errors %}
<div class="flash">{{ error }}</div> 
{% endfor %}      
{% endif %}
<div class="form-field">{{ form.name.label }} {{ form.name }}  </div>
<br>
<div class="form-field">{{ form.email.label }} {{ form.email }} </div>
<br>
<div class = "form-field">{{ form.chat_file.label}} {{ form.chat_file }} </div>
<br>
{{ form.submit }}

</form>
</div>
<br>
<h2 class="title">How does it work ?</h2>
<h2><img src="////Users/louisalu/Documents/text/internal_sms_analysis/part1.png" alt="Explanations" width="700" height="200"></h2>
<h2 class="title">What does it analyze?</h2>
<h3>Ultimate Quality Indicator: a summary score to test the health of your text conversation</h3>
<h3><img src="final_score.png" alt="Final Score" width="700" height="500"></h2>
<h3>Text Ratio: How is texting more ? </h3>
<h3><img src="message_ratio.png" alt="Message Ratio" width="700" height="500"></h2>
<h3>Initiation Score: Who initiates more ? </h3>
<h3><img src="initiation.png" alt="Initiation Ratio" width="700" height="500"></h2>
<h3>Sentiment: Are you having a good time talking to your partner ? </h3>
<h3><img src="sentiment.png" alt="Sentiment Score" width="700" height="500"></h2>
<h3>Holy Grail: How many holy grail conversations are you having ? </h3>
<h4>*Holy Grail conversations are high quality text conversations</h4>
<h3><img src="holygrail.png" alt="Holy Grail Conversation" width="700" height="500"></h2>
<h3> And so much more indicators all in the reports </h3>

<h2 class="title"> Questions? Please email: erpsystem.msg@gmail.com </h2?
</html>

图像中出现错误,我试图指定图像的整个路径,但仍然没有显示。

这是css样式表,保存在另一个文件夹下:

@import url(https://fonts.googleapis.com/css?family=Montserrat:400,700);
* { 
background-color: #E7717D;
font-family: Helvetica, Arial, sans-serif;
color: white;
text-align: center;
}
form { max-width:420px; margin:50px auto; }
.title{
color:white;
font-family: Helvetica, Arial, sans-serif;
font-weight:600;
font-size: 20px;
border-radius: 5px;
line-height: 22px;
background-color: #4F81BD;
border:2px solid #4F81BD; */
transition: all 0.3s;
padding: 13px;
margin-bottom: 15px;
width:100%;
box-sizing: border-box;
outline:0;

}
.form-field {

color:#D4FCA4;
font-family: Helvetica, Arial, sans-serif;
font-weight:500;
font-size: 18px;

border-radius: 5px;
line-height: 22px;
background-color: transparent;
border:2px solid #D4FCA4;

transition: all 0.3s;
padding: 13px;
margin-bottom: 15px;
width:100%;
}
input {
background-color: #E7717D;
border:2px solid #D4FCA4
}
/* .form-field:focus { border:2px solid #CC4949; } */

[type="submit"] {
font-family: 'Montserrat', Arial, Helvetica, sans-serif;
width: 100%;
background:#C2B9B0;
border-radius:5px;
border:0;
cursor:pointer;
color:white;
font-size:24px;
padding-top:10px;
padding-bottom:10px;
transition: all 0.3s;
margin-top:-4px;
font-weight:700;
}
[type="submit"]:hover { background:#4F81BD }
/* Message flashing */
.flash {
background-color: #C3073F;
padding: 10px;
width: 102%;
}

在Flask中,图像文件必须存储在静态文件夹中。将图像上载到静态文件夹。指定整个路径将不起作用。

<img src="static/yourImageName.jpg" />

相关内容

  • 没有找到相关文章