沉默的老吴啊 2022-01-12 12:47 采纳率: 66.7%
浏览 55
已结题

网页出现问题了,试了好多种方法

网页

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>主界面</title>
    <link rel="stylesheet" href="static\css\水波.css">
    <!--<link rel="shortcut icon" href="static\mario.ico" type="image/x-icon">-->
</head>
<body background="static\images\bg2.png"  style="background-repeat:no-repeat ; background-size:100% 100% ; background-attachment:fixed">

<div>
    <a href="/shezhi" style="text-align:right">
        <img src="static\images\hb2.png" alt="图片丢失" title="设置" style="height:150px ; weight:150px">
    </a>

</div>


</body>
</html>

Python代码

from flask import Flask, render_template, request, redirect
import random as a1

app = Flask(__name__)


#获取文本自定义行
def hang(a):
    f = open("txt/数据.txt", "r")
    r = f.readlines()
    b = print(r[a])  # 读第一行
    return b

# 修改文本自定义行
def changetext(a, b):
    with open('txt/数据.txt', 'r') as f:
        lines = []  # 创建了一个空列表,里面没有元素
        for line in f.readlines():
            if line != '\n':
                lines.append(line)
        f.close()
    with open('txt/数据.txt', 'w') as f:
        for line in lines:
            if a in line:
                line = b
                f.write('%s\n' % line)
            else:
                f.write('%s' % line)


# 定义开始界面
@app.route('/')
def main():
    print(hang(0))
    if hang(0) == 'white' or hang(0) == 'None':
        return render_template('主页面.html',bg='bg')
    elif hang(0) == 'yello':
        return render_template('主页面.html', bg='bg2')


@app.route('/shezhi')
def s1():
    return render_template('设置.html')


@app.route('/shezhicg')
def s2():
    bgc = request.args['bg']
    print(bgc)
    b1 = hang(0)
    changetext(b1,bgc)
    return redirect('/')


if __name__ == '__main__':
    app.run()


[2022-01-12 12:46:55,901] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1953, in full_dispatch_request
    return self.finalize_request(rv)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1968, in finalize_request
    response = self.make_response(rv)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 2098, in make_response
    "The view function did not return a valid response. The"
TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.
127.0.0.1 - - [12/Jan/2022 12:46:55] "GET / HTTP/1.1" 500 -
127.0.0.1 - - [12/Jan/2022 12:46:56] "GET /favicon.ico HTTP/1.1" 404 -


文件路径

img

  • 写回答

2条回答 默认 最新

  • 崽崽的谷雨 2022-01-12 13:56
    关注

    具体什么问题,你这个时 python报错吧

    TypeError:view函数未返回有效响应。函数返回None或结束时没有返回语句。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 4月23日
  • 已采纳回答 4月15日
  • 创建了问题 1月12日

悬赏问题

  • ¥15 如何提取csv文件中需要的列,将其整合为一篇完整文档,并进行jieba分词(语言-python)
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?