0

I have an issue in Flask. I have my html, css and js files in the same folder and same directory as my python file. I have no templates/static folder as such. When I do this in flask:

app = Flask(__name__, template_folder='.', static_folder='.')

My html gets rendered correctly, but when I open the link the css and js don't get added to the html. They are linked in the html as

<link rel="stylesheet" type="text/css" href= "index.css"> and <script src="final.js"></script> 

File names are absolutely the same. What am I doing wrong?

I tried what chatGPT said, it isnt working. I am on linux/ubuntu if that is of any significance. I would really appreciate the help.

moken
  • 3,227
  • 8
  • 13
  • 23
xyz
  • 1
  • Welcome to StackOverflow! Why don't you want to use the common setting with a static folder? You might want to try the folder structure suggested in the issues [13772884](https://stackoverflow.com/questions/13772884/css-problems-with-flask-web-app) and [22259847](https://stackoverflow.com/questions/22259847/application-not-picking-up-css-file-flask-python) – Daniel Kettemann May 04 '23 at 10:52

1 Answers1

0

You are trying to directly link the CSS and javascript file like a normal HTML page, in Flask u could try this below link and script tag, change the file path of js and CSS file

<script src="{{url_for('static',filename='js/scripts.js')}}"></script>
<link href="{{url_for('static',filename='css/styles.css')}}" rel="stylesheet" />