Ask coding questions

← Back to all posts
Why is the html not connecting to the js and css files?
VulcanWM (2766)

The repl is here:
The output where the css and is should be seen is
How do I make it connect to the js and css?
Any help appreciated
Thanks 🙏

Answered by JBloves27 (1884) [earned 5 cycles]
View Answer
JBloves27 (1884)

You should do the following to the href:

<link href="{{ url_for('static', filename='static/style.css') }}" rel="text/css"/>

And for the app = Flask(__name__), do this:

app = Flask(__name__,

That should work! :)

VulcanWM (2766)

What about the js tho? @JBloves27

JBloves27 (1884)

@VulcanWM, because js is included in static as well, it would be the same href, except like this:

<script href="{{ url_for('static', filename='static/index.js') }}" rel="text/css"></script>
VulcanWM (2766)

Tried that but have a new error now ;-; @JBloves27

JBloves27 (1884)

Try adding the html code you have right now along with standard html template, like <head>, <html>, and <body> @VulcanWM

JBloves27 (1884)

heres the final result. You might wanna tinker with the jquery tho, because it doesnt seem like its working ;) @VulcanWM

VulcanWM (2766)

Wait it keeps on linking to /languages/german/family/static/germanfamily.js @JBloves27

JBloves27 (1884)

Try making another route that returns a render_template value. Like for example:


def route():
  return render_template(

That should work, as it returns the same variable with new values. Just make another html file, and route it to the file name, and do the same you did with the first route/file. @VulcanWM

JBloves27 (1884)

np! let me know it it works! :) @VulcanWM

Coder100 (18168)

Like most things, you do not need the static folder. All the contents in the static folder are served, but not the folder itself

<link href="/style.css">
JBloves27 (1884)

When you use flask tho, shouldn't you use template folders and static folders? @Coder100

Coder100 (18168)

did i say they shouldn't be in those folders? @JBloves27

JBloves27 (1884)

ik, but in regular flask apps, arent you supposed to use static files? or no? @Coder100

Highwayman (1482)

Um. wh- make a path to the static folder in your server? @app.route("static/*") or something? Is Flask supposed to implicitly server the static folder?