0

I am working on my pet-project which is supposed to take user's data from web page and show the result (calculated on python). I just do not know how to connect my python code with html+css+js page.

I have read a lot of articles, watched videos on YouTube. As a result, I understood that the main technologies I'm going to use are cgi, flask and py-script. So, I've added all of them to my project as I'm a beginner.

I am adding my repo on github

https://github.com/5724gnvasya/Decision-support-system ,

where are all files, which you can open on your VSCode, for example.

When I'm writing on the terminal

cd src
python app.py

all needed calculations are working correctly (but css file is not - Failed to load resource: the server responded with a status of 404 (NOT FOUND)).

When I click Go Live in the lower right corner in VSCode, all html, css, js are working, but python calculations are not - Failed to load resource: the server responded with a status of 405 (Method Not Allowed).

I really do not know how to fix that. How to make correct calculations displayed on my beautiful page (html+css+js)? Please help me. I will be very grateful!

3
  • 1
    could you post the full traceback? this will contain information about what line is giving the error. The error is telling you that a server replied that a requested resource was not found. Either you provided an incorrect address or the resource is no longer available in that server. Commented Jan 12, 2024 at 10:54
  • I'm afraid the console does not show me the exact line of the mistake. Moreover, after changing the structure of the files my css stopped working, telling Refused to apply style from 'http://127.0.0.1:5500/src/%7B%7B%20url_for('static',%20filename='/src/css/style_main_page.css')%20%7D%7D' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled. Commented Jan 14, 2024 at 22:17
  • don't add relevant information as comments. Edit your question and provide all necessary information there. The error in the comment is completely different than the one in the question, since it refers to an incorrect MIME type, but you haven't posted your CSS file, so we cannot check it. Commented Jan 15, 2024 at 8:12

1 Answer 1

0

The problem is with where you're storing your static files (images, JS and CSS).

Flask requires that you store these static files in the static directory, as explained in the documentation. That way, you'll be able to access your CSS.

The first thing you need to do is change your project structure.
It currently looks like this:

└── src/
    └── css/
    └── icons/
    └── img/
    └── js/
    └── templates/
    └── app.py

You will need to change it to:

└── src/
    └── static/
        └── css/
        └── icons/
        └── img/
        └── js/
    └── templates/
    └── app.py

Once you've done that, change how you're calling your static files to something like:

<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/style_main_page.css') }}">
Sign up to request clarification or add additional context in comments.

8 Comments

Thank you for your answer, but it did not resulted in a success( I added <link rel= "stylesheet" type= "text/css" href= "{{ url_for('flaskr/static',filename='/css/style.css') }}"> and changed the structure as you said, but it did not help
I have added flaskr folder which contains static as this is stated in documentation you provided (hope I understood it correctly). But it works the same as when I did it with only static folder.
flaskr is an example directory used in the documentation. In your case, you should create the static directory in the src directory, at the same level as templates/ and app.py (as shown in the answer above). Once you've done that, run the command python app.py
I did it, but it still replies Failed to load resource: the server responded with a status of 405 (Method Not Allowed)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.