0

so I have tried paying some tutors to look at this and they cannot seem to find the issue. I have a really good feeling it is a directory issue.

Folder directory organization

App.py is outside all folders, inside a template folder is pricing.html, outside is another folder named css which has pricing.css.

I run my app.py which loads pricing.html to be able to press a button which goes to stripe checkout. The issue is, app.py finds the pricing folder, but the pricing.css does not load. Here is the html code in pricing.html:

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

Here is the app.py code:

from flask import Flask, redirect, request, render_template

import stripe

app = Flask(__name__,static_url_path="",static_folder="templates")

stripe.api_key = 'sk_test_51KzqK9Hj2B2Quz911XrP11cB4Jb2ESrDCelSpRIZBqa18TWO9bGKlyuWsmiNeGYEHw4224xx5ghUWDaTQOukRjcf00rHXcZGYU'

YOUR_DOMAIN = "http://localhost:5000"

@app.route('/create-checkout-session', methods=['POST'])
def create_checkout_session():
    try:

        checkout_session = stripe.checkout.Session.create(
            line_items = [
                {
                    'price': 'price_1KzrAtHj2B2Quz91wMDanJjz',
                    'quantity':1
                }
            ],
            mode="payment",
            success_url=YOUR_DOMAIN + "/success.html", 
            cancel_url=YOUR_DOMAIN + "/cancel.html"
        )
    except Exception as e:
        return str(e)

    return redirect(checkout_session.url,code=303)

if __name__== "__main__":
    app.run(port=5000,debug=True)

If I move the css folder inside the templates folder, the css will load, but I would have to change the html to all the other template and also I like this folder organization. Any thoughts?

Here is what is returned in terminal when I run it:

    • [20/May/2022 18:04:50] "GET /pricing.html HTTP/1.1" 200 -
    • [20/May/2022 18:04:51] "GET /css/style.css HTTP/1.1" 404 -
    • [20/May/2022 18:04:51] "GET /css/Pricing.css HTTP/1.1" 404 -
    • [20/May/2022 18:04:51] "GET /javascript/jquery.js HTTP/1.1" 404 -
    • [20/May/2022 18:04:51] "GET /javascript/nicepage.js HTTP/1.1" 404 -
    • [20/May/2022 18:04:51] "GET /css/images/GainesOpusInstitute4.png HTTP/1.1" 404 -
  • https://stackoverflow.com/questions/22259847/application-not-picking-up-css-file-flask-python I have tried this and it doesn't work for me because it just translate the code in a weird encrypted way. – Kaden Gaines May 20 '22 at 22:29
  • The directory layout seems alright, when you go to the website in browser do you see the ``? – SleepyStew May 21 '22 at 09:39
  • Yes, when I go to the console, I see the line of code – Kaden Gaines May 21 '22 at 16:11

1 Answers1

0

I believe that for flask to serve your css file it needs to be in the /static directory. Try moving your /css and /javascript folders into a directory at the same level called /static. Then change your link to be:

<link rel="stylesheet" type="text/css" href="/static/css/style.css" media="screen">

See https://flask.palletsprojects.com/en/2.1.x/quickstart/#static-files for more info.

SleepyStew
  • 116
  • 5