Click here to Skip to main content
15,122,218 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a program in python, which is an online store which users can add products to their cart and checkout etc.

For the final part I want to finish it with it set up in flask for its own web page.



        <pre lang="Python">
        from flask import Flask
        from delivery import *
        app = Flask(__name__)

        @app.route("/")

        class Main():
             def StartMessage(self):
                 while True:
                     print('''
                              Welcome to The Toy Store

                             Please select which action you would like:
                             1. View store products
                             2. Add item to Shopping Cart
                             3. View Shopping Cart
                             4. Remove item from Shopping Cart
                             5. Calculate Shopping Cart
                             6. Checkout
                             7. Delivery 
                             8. Check product availability
                             9. Exit
                                ''')

                     selection = int(input("Select which action: "))

                     if selection == 1:
                        Products.listProducts(self)

                     elif selection == 2:
                        ShoppingCart.add_products(self)

                     elif selection == 3:
                        ShoppingCart.displayCart(self)

                     elif selection == 4:
                        ShoppingCart.removeitem(self)

                     elif selection == 5:
                        ShoppingCart.totalprice(self)

                     elif selection == 6:
                        Delivery.checkout(self)

                     elif selection == 7:
                        ShoppingCart.postage(self)

                     elif selection == 8:
                        ShoppingCart.check_stock(self)

                     elif selection == 9:
                        print(" Thank you for visiting The Toy Store, we hope to see you again")
                        break

                    else:
                       print("Invalid selection, please try again")
                       break


        startmessage = Main()
        startmessage.StartMessage()


What I have tried:

Looking online for various tutorials I managed to get the obligatory hello world response on the webpage, I thought if I changes this to add my start message function which welcomes users and lets them pick which action to take it would start on a webpage, however running this the function just works inside the terminal it does not provide the flask root to open up a web page.
Posted
Updated 22-Oct-21 4:15am

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900