Ask coding questions

← Back to all posts
I have a two problems with flask and HTML
isaiah08 (63)

I am gettting an error when trying to connect a flask form with an html template. It is doing the job i want (writing the email into a file) but it still gives the internal server error page. My problem with html is that i can't connect my style sheet to my html page. If you go to line 9 in index.html, I use

<link rel="stylesheet" type="text/css" href="/templates/style.css">

to connect the style.css in the templates folder. But it doesn't connect. Am i writing the directory wrong?

Answered by k9chelsea2 (785) [earned 5 cycles]
View Answer
k9chelsea2 (785)

put the css in a folder named static then do

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

this should work

isaiah08 (63)

I decided to do SQL for the email part. @isaiah08

isaiah08 (63)

Question: does a .txt file that i have writen into using filename.write() clear after one hour? I have heard about this but never actually seen it happen. @k9chelsea2

MocaCDeveloper (561)

Put any .cc or .js files in a folder titled “static”
Then, when you want to use it, do:

<link rel=“stylesheet” href=“{{url_for(‘static’, filename=‘style.css’}}”

Any changes to the files within the static folder, however, will then require you to clear your browsing cache because for some reason flask doesn’t update it like Nodejs servers do.

Coder100 (17111)

Put the style.css in a different folder:


all static files go somewhere else!

And for your HTML:

<link rel="stylesheet" type="text/css" href="style.css" />
Whacko (320)

Oh. Try replacing it with this:

<link rel="stylesheet" type="text/css" href="style.css" />
isaiah08 (63)

Hmm... it's still not working. Thanks anyways! @Whacko

Whacko (320)

@isaiah08 Weird-Invite me to the repl.

isaiah08 (63)

I added you to a copy. @Whacko