简体   繁体   中英

Getting error 404 while trying to run flask app in python

attached is the picture of how my directories are up i am trying to run my app with flask, and I am referencing the proper directories, yet I keep getting an error 404 message. I do not know what I am doing wrong.

Here is my the code to run the app in the app.py section:

    @app.route('/')
    def math():
        #return(y)
        return render_template('index2.html', variable = y)

    if __name__ == "__main__":
        app.run(debug = True)

and here is my html code

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

<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="">

  <title>Scrolling Nav - Start Bootstrap Template</title>

  <!-- Bootstrap core CSS -->
  <link href="/static2/static2/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">

  <!-- Custom styles for this template -->
  <link href="/static2/static2/css/scrolling-nav.css" rel="stylesheet">


  <!-- Bootstrap core JavaScript -->
  <script src="/static2/static2/vendor/jquery/jquery.min.js"></script>
  <script src="/static2/static2/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

  <!-- Plugin JavaScript -->
  <script src="/static2/static2/vendor/jquery-easing/jquery.easing.min.js"></script>

  <!-- Custom JavaScript for this theme -->
  <script src="/static2/static2/js/scrolling-nav.js"></script>

</body>

</html>

the scrolling -nav.js is in the correct folder for sure.

Please let me know if there is more information needed for this question.

For references to static files in Flask it's considered best practice to use the url_for function eg

<script src="{{url_for('static', filename='js/scrolling-nav.js')}}"></script>

Other than that, if that is your full HTML then it's just a javascript file, do you have the basic HTML stuff in there as well? eg

<!DOCTYPE html>
<html lang="en">
    <head>
    </head>
    <body>
    Content
    </body>
<html>

Is index2.html stored in a templates folder?

I got it. My directories name was static2. The directories name must be "static" for the css and js files to be pulled.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM