0

While loading in my flask app I'm getting an internal server 404 GET error. The files that it claims are missing are exactly where they are listed not to be.

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 -

I have my app.run() at the end of my app.py so it's not that.

I'm using a main bootstrap template HTML file that all other HTML files extend from. This is the only place my code loads the 'missing js files. Here it is(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>

Here is my app.py file:

#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', methods=['GET', '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', form=form,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)

I have run out of ideas for what the issue could be so I hope someone here can help me.

Thank you and have a good day.

Aviv T
  • 5
  • 2

0 Answers0