GET 404无法在Flask Bootstrap中加载资源错误

问题描述

在我的烧瓶应用程序中加载时,出现内部服务器404 GET错误。它声称丢失的文件正是未列出的文件

127.0.0.1 - - [06/Sep/2020 08:05:28] "GET /static/bootstrap/js/bootstrap.bundle.min.js HTTP/1.1" 404 -
127.0.0.1 - - [06/Sep/2020 08:05:28] "GET /static/bootstrap/css/bootstrap.min.css.map HTTP/1.1" 404 -
127.0.0.1 - - [06/Sep/2020 08:05:28] "GET /static/bootstrap/js/bootstrap.bundle.min.js HTTP/1.1" 404 -

我在app.py的末尾有我的app.run(),所以不是那样。

我正在使用主要的引导程序模板HTML文件,所有其他HTML文件都从该文件扩展而来。这是我的代码加载“缺少js文件”的唯一位置。这是(base.html):

<!DOCTYPE html>
<html lang="en">

<head>
  
  {%block head%}
  <Meta charset="utf-8">
  <Meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
  <Meta name="description" content="">
  <Meta name="author" content="">
  <!-- Bootstrap core CSS -->
  <link href="{{ url_for('static',filename='bootstrap/css/bootstrap.min.css') }}" rel="stylesheet">

  <!-- Custom styles for this template -->
  <title>{%block title%}{{title1}}{%endblock%}</title>
  {%endblock%}
  

</head>

<body>

  <!-- Navigation -->
  <nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
    <div class="container">
      <a class="navbar-brand" href="#">{{title1}}</a>
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>
      <div class="collapse navbar-collapse" id="navbarResponsive">
        <ul class="navbar-nav ml-auto">
          <li class="nav-item active">
            <a class="nav-link" href="{{url_for('main_timeline')}}">Home
              <span class="sr-only">(current)</span>
            </a>
          </li>
          <li class="nav-item active">
            <!--{% if current_user.is_authenticated %}
            <a class="nav-link" href="{{url_for('dashboard')}}">{{ current_user.username }}
              <span class="sr-only">(current)</span>
            </a>
            {% else %}
            <a class="nav-link" href="{{url_for('login')}}">Log In
              <span class="sr-only">(current)</span>
            </a>

            {% endif %}-->
            <a class="nav-link" href="{{url_for('login')}}">Log In
              <span class="sr-only">(current)</span>
            </a>
            
          </li>
          <li class="nav-item active">
            <a class="nav-link" href="{{url_for('signup')}}">Signup
              <span class="sr-only">(current)</span>
            </a>
          </li>
        </ul>
      </div>
    </div>
  </nav>

  <!-- Page Content -->
  <div class="container">
    {%block content%}
    {%endblock%}
  </div>
  <div id="footer">
    {% block footer %}
    <footer class="py-5 bg-dark">
      <div class="container">
        <p class="m-0 text-center text-white">&copy; copyright 2020 by <a href="#">Fizzy Bubalech</a>.</p>
      </div>
    
    {% endblock %}
</div>

  <!-- Bootstrap core JavaScript -->
  <script src="{{url_for('static',filename = 'jquery/jquery.slim.min.js') }}"></script>
  <script src="{{url_for('static',filename = 'bootstrap/js/bootstrap.bundle.min.js') }}"></script>

</body>

</html>

这是我的app.py文件

#All imports for this file

#Imports for the flask libraries
from flask import Flask,flash
from flask import render_template,redirect,url_for
from flask_login import LoginManager,UserMixin,login_user,login_required,logout_user,current_user
from flask_bootstrap import Bootstrap

#Imports from the local file databases.py
from databases import get_all_posts,get_post,get_user,add_user

#Imports for the local file forms.py
from forms import Login_form,Register_form

#imports for the werkzeug Library 
from werkzeug.security import generate_password_hash,check_password_hash

#imports for os commands
import os

#init app setup
app = Flask(__name__)
app.config['SECRET_KEY'] = os.urandom(24)
Bootstrap(app)
login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = 'login'

#setup user loader
@login_manager.user_loader
def load_user(user_id):
    return get_user(int(user_id))

#login page function and route
@app.route('/login',methods=['GET','POST'])
def login():
    form = Login_form()
    if form.validate_on_submit():
        user = get_user(form.username.data)
        if user:
            if check_password_hash(user.password,form.password.data):
                login_user(user,remember=form.remember.data)
                print("Login Successful")
                return redirect(url_for('dashboard'))
        print("Login Failed")
        return None
        #return '<h1>' + form.username.data + ' ' + form.password.data + '</h1>'

    return render_template('login_page.html',form=form,title1 = "Login")

#main page timeline with all posts function and route
@app.route('/')
def main_timeline():
    return render_template('main_timeline.html',posts = get_all_posts(),title1 = "The Timeline")

#signup page function and route
#Todo_test sigup
@app.route('/signup','POST'])
def signup():
    form = Register_form()

    if form.validate():
        hashed_password = generate_password_hash(form.password.data,method='sha256')
        add_user(form.username.data,form.email.data,hashed_password)

        return redirect(url_for('dashboard'))
        #return '<h1>' + form.username.data + ' ' + form.email.data + ' ' + form.password.data + '</h1>'

    return render_template('signup_page.html',title1 = "Sign Up")

#??????????
@app.route('/test')
def test():
    form = Login_form()
    return render_template("login.html",form = form)

#user dashboard(login required) function and route
@app.route('/dashboard')
@login_required
def dashboard():
    posts = get_all_posts()
    for post in posts:
        if post.user_id != current_user.id:
            post.pop()
    render_template('dashboard.html',posts = posts)

#Post page function and route
@app.route('/post:<id>')
def load_post(id):
    return render_template("post_page.html",posts = [get_post(id)],title1 = get_post(id).post_name)

#run app on file complition 
if __name__ == '__main__':
    app.run(debug = True)

对于可能出现的问题,我已经没有足够的想法了,希望我能在这里为我提供帮助。

谢谢,祝你有美好的一天。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)