Ask coding questions

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

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 (770) [earned 5 cycles]
View Answer
k9chelsea2 (770)

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 (86)

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

isaiah08 (86)

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 (704)

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 (18782)

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 (325)

Oh. Try replacing it with this:

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

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

Whacko (325)

@isaiah08 Weird-Invite me to the repl.

isaiah08 (86)

I added you to a copy. @Whacko