1
\$\begingroup\$

I'm a beginner in programming and I'm figuring out what is the best approach for my mini e commerce site project.

My current approach is

{% for i in item %} <!-- where item = database fetchall -->

<h3> {{i[0]}} </h3> <!-- product name -->
<p> {{i[3]}} / kg</p> <!-- product price -->
<form action = "/send" method = "post">
<input type = "number" class = "form-control" min = 0 max = 100> 
</input>
<button type = "submit" class = "btn btn-primary">Add to cart </button>
{% endfor %}

Something similar to that, and I'm doing all the work (shop, cart, checkout) with python and flask session.

This is my whole backend for storing session

def sendPage():
    if "iterate" in session:
        pass
    elif "iterate" not in session:
        session["item"] = []    
        
    session["iterate"] = "no"
    if request.method == "POST":
        for i in result: 
            try:
                if f"{i[0]}qty" in session:
                    session[f"{i[0]}qty"] += int(request.form[f"{i[0]}"])
                    print("Ping")
                    if f"{i[0]}" not in session["item"] and session[f"{i[0]}qty"] >= 1:
                        session["item"].append(f"{i[0]}")
                    
                
                else:   
                    session[f"{i[0]}qty"] = int(request.form[f"{i[0]}"])
                    print("Pong")
                    if f"{i[0]}" not in session["item"] and session[f"{i[0]}qty"] >= 1:
                        session["item"].append(f"{i[0]}")
                    elif f"{i[0]}":
                        pass
                    

Now that I am learning JavaScript, is it a better approach using it? Or flask session just works fine? What are the future problems this type of approach will face?

Any advice would be reallly really helpful~

\$\endgroup\$
1
  • \$\begingroup\$ I currently have it deployed on winmarimanzano.pythonanywhere.com but wondering it is due to my free subscription / internet connection or the code itself that is causing for it to load slowly. p.s the cartpage needs 'chayote' or 'carrots' or 'cabbage' for it to enter (since I haven't expanded my if statements yet) \$\endgroup\$ Jun 28 at 3:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.