Nopy. 2022-05-18 02:11 采纳率: 0%
浏览 146
已结题

flask中怎么实现layui框架页面的来回切换

问题遇到的现象和发生背景

img


我想要在flask中实现这种多个页面的切换,本来用超链接就可以,但是在layui框架中,我发现只有用url_for才起作用,可是只有一个页面起作用,其他都layui相关的全部404

######这是我app.py里的构造


```python
from flask import Flask, render_template, jsonify, request, redirect, url_for
import config
import utils

app = Flask(__name__)
app.config.from_object(config)


@app.route('/', methods=['get', 'post'])
def index():  # put application's code here
    labels = ['名字', '经度', '纬度']
    content = utils.get_sk()
    # content = [i[0] for i in content]
    if request.method == 'post':
        return redirect(url_for('main1'))
    return render_template("index.html", labels=labels, content=content)
@app.route('/main1', methods=['get', 'post'])
def main1():  # put application's code here
    return render_template("main.html")


@app.route('/main1/11/')
def shuiku1():
    return render_template("shuiku1.html")

@app.route('/main1/12/')
def shuiku2():
    return render_template("shuiku2.html")

@app.route('/main1/13/')
def shuiku3():
    return render_template("shuiku3.html")

@app.route('/main1/21/')
def temp1():
    return render_template("temp1.html")

@app.route('/main1/22/')
def temp2():
    return render_template("temp2.html")

@app.route('/main1/23/')
def temp3():
    return render_template("temp3.html")

@app.route('/main1/24/')
def temp4():
    return render_template("temp4.html")


@app.route('/main1/<is_where>/', methods=['get', 'post'])
def question(is_where):  # put application's code here
    if request.method == 'POST':
        if is_where == '11':
            return redirect(url_for('shuiku1'))
        elif is_where == '12':
            return redirect(url_for('shuiku2'))
        elif is_where == '13':
            return redirect(url_for('shuiku3'))
        elif is_where == '21':
            return redirect(url_for('temp1'))
        elif is_where == '22':
            return redirect(url_for('temp2'))
        elif is_where == '23':
            return redirect(url_for('temp3'))
        elif is_where == '24':
            return redirect(url_for('temp4'))
        else:
            return redirect(url_for('index'))


###### 运行结果及报错内容 
这样就会导致layui.css404
想问一下有没有大佬有什么解决方法
  • 写回答

3条回答 默认 最新

  • hyh123a 全栈领域新星创作者 2022-05-18 09:48
    关注

    看一下控制台里的网络接口URL是什么路径,
    或者控制台什么报错

    评论

报告相同问题?

问题事件

  • 系统已结题 5月26日
  • 赞助了问题酬金10元 5月18日
  • 创建了问题 5月18日

悬赏问题

  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿