问题遇到的现象和发生背景
在xes的python编辑器里面,内存只有20M,在以前都可以的情况下,最近一次报了500错误
问题相关代码,请勿粘贴截图
main.py
from flask import Flask,render_template,request,redirect,session
from getnews import get_news
import pickle
app = Flask(__name__)
#设置秘钥
app.config['SECRET_KEY']='**##$$..tuiio23'
@app.route("/logout")
def logout():
session.clear()
return redirect("/")
ids=[{"name":"admin","pwd":"123456"},{"name":"UT","pwd":"aiyayouchoule"},{"name":"小震","pwd":"wenxinshimvp"},{"name":"陈文忻","pwd":"xiaozhenniubi"}]
#{
#设置登录入口路由,响应HTML页面
@app.route("/login")
def login_enter():
return render_template('login.html')
#设置用户登录路由,响应登录是否成功
@app.route("/loginpost",methods=["POST"])
def login():
name = request.values.get("user")
pwd = request.values.get("pwd")
for cwx in ids:
if name==cwx["name"] and pwd==cwx["pwd"]:
session["name"] = name
return redirect("/")
return render_template("fail.html")
# 读取pickle文件中保存的留言
try:
with open("messages.pickle",'rb') as f:
messages = pickle.load(f)
except:
messages = []
# 呈现和保存留言
@app.route("/messageboard")
def message_board():
name = request.values.get("who")
text = request.values.get("text")
if name and text:
message = {"name":name,"text":text}
messages.append(message)
with open("messages.pickle",'wb') as f:
pickle.dump(messages,f)
return render_template("messageboard.html",messages = messages)
#删除留言
@app.route("/delmsg")
def del_msg():
msgtext = request.values.get("text")
for msg in messages:
if msg["text"] == msgtext:
messages.remove(msg)
with open("messages.pickle","wb") as f:
pickle.dump(messages,f)
return redirect("/messageboard")
#读取pickle文件中保存的作品
try:
with open("works.pickle","rb") as f:
works = pickle.load(f)
except:
works = []
# 默认网址对应的路由
@app.route('/')
def index():
hot_news = get_news()
return render_template("index.html", news = hot_news[:7:1],works = works)
@app.route("/redian")
def re():
r=get_news()
return render_template("redian.html",new=r)
@app.route("/uploadwork")
def upload_work():
return render_template("uploadwork.html")
@app.route("/processwork",methods=["POST"])
def process_work():
title = request.values.get("title")
link = request.values.get("link")
object = request.files.get("file")
if title and link and object:
fname = object.filename
object.save("static/images/"+fname)
new_work = {"title":title,"link":link,"file":fname}
works.append(new_work)
with open("works.pickle","wb") as f:
pickle.dump(works,f)
return redirect("/")
else:
return render_template("uploadwork.html")
@app.route("/delete")
def del_work():
work_title = request.values.get("worktitle")
for work in works:
if work["title"] == work_title:
works.remove(work)
with open("works.pickle","wb") as f:
pickle.dump(works,f)
return redirect("/")
#}
app.run()
index.html
getnews.py
def get_news():
import requests #导库不说了
import bs4
response = requests.get("https://top.baidu.com/board?tab=realtime")
soup = bs4.BeautifulSoup(response.text, "lxml")
data = soup.find_all(name="a", class_="title_dIF3B")
da=soup.find_all(name="a",class_="img-wrapper_29V76")
#爬虫区
#————————————————分————界————线——————————————————
#算法区
l1=[]
l2=[]
d={}
try:
#典型的给字典添加元素
for n in data:
l1.append(n.text)
for n1 in da:
l2.append(n1["href"])
for i in range(max(len(l1),len(l2))):
d[l1[i]]=l2[i]
return d
except:
return "获取失败"
CSS、JS等起美化作用的和HTML没有展示
运行结果及报错内容
内部服务器错误
服务器遇到内部错误,无法完成您的请求。服务器过载或应用程序出错。
我的解答思路和尝试过的方法
其实以前我还弄得三个音乐,占用了5M
我认为是因为内存太多导致的,但去掉5M后还报500错误,请问这是怎么回事
我想要达到的结果
不要报错就行