Hi! i'm doing a final project for a university introduction course in web programmation.

I'v Coded this:

class MainHandler(BaseHandler):

    def get(self):
        #product_comments = Comments().get_all()
        user = users.get_current_user()
        if user:
            member = Members().get_by_id(user.user_id())
        baskets=Baskets().get_by_member(member)
        template_args = {'baskets': baskets}
            
        products = Products().get_all()
        product_comments = []
        for product in products:
            comments = Comments().get_by_product(product)
            product_comments.append(comments)
          
        template_args = {'product_comments': product_comments}
        self.render('main.html', template_args)

I've got this:

Traceback (most recent call last):
File "C:\Program Files\Google\google_appengine\google\appengine\ext\webapp\__init__.py", line 634, in __call__
handler.get(*groups)
File "C:\Users\DACOT153\Desktop\ULaval\Session 6 - H2011\SIO - 3103 Z1 Introduction a la programmation Web\Exercice\GeekShop3\GeekShop3\src\handler_main.py", line 27, in get
baskets=Baskets().get_by_member(member)
UnboundLocalError: local variable 'member' referenced before assignment


I'm a newbie in programming and i really don't understand what's going on! can someone help please?

I use Python 2.5 and google App Engine

Thx!

If you want to see the complete python script:

from handler_base import BaseHandler
from google.appengine.ext import webapp
from google.appengine.api import users
from google.appengine.ext.webapp import util
from model_basket import Baskets
from model_member import Members
from model_product import Products
from model_comment import Comments
class AboutHandler(BaseHandler):

    def get(self):
        self.render('about.html')

class MainHandler(BaseHandler):

    def get(self):
        product_comments = Comments().get_all()
        user = users.get_current_user()
        if user:
            member = Members().get_by_id(user.user_id())
        baskets=Baskets().get_by_member(member)
        template_args = {'baskets': baskets}
            
        products = Products().get_all()
        product_comments = []
        for product in products:
            comments = Comments().get_by_product(product)
            product_comments.append(comments)
          
        template_args = {'product_comments': product_comments}
        self.render('main.html', template_args)
        
def main():
    application = webapp.WSGIApplication([('/about', AboutHandler), 
                                          ('/.*', MainHandler)
                                          ], 
                                          debug = True
                                          )
    util.run_wsgi_app(application)

if __name__ == '__main__':
    main()

OKAY!!! Nevermind!!! I found the solution!!!! :D
Here is the solution:

class MainHandler(BaseHandler):

    def get(self):
        product_comments = Comments().get_all()
        user = users.get_current_user()
        if user:
            member = Members().get_by_id(user.user_id())
        baskets=Baskets().get_by_member(0)
        template_args = {'baskets': baskets}
            
        products = Products().get_all()
        product_comments = []
        for product in products:
            comments = Comments().get_by_product(product)
            product_comments.append(comments)
          
        template_args = {'product_comments': product_comments}
        self.render('main.html', template_args)
        
def main():
    application = webapp.WSGIApplication([('/about', AboutHandler), 
                                          ('/.*', MainHandler)
                                          ], 
                                          debug = True
                                          )
    util.run_wsgi_app(application)

if __name__ == '__main__':
    main()

Please mark this thread "Solved".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.