Re: Error: 'module' object is not callable
On Fri, Apr 27, 2012 at 4:03 PM, bruno desthuillierswrote: > On Apr 27, 2:30 pm, Tom Evans wrote: >> >> The datetime class lives inside the datetime module. > > So far so good but! > >> You must have >> "import datetime" in that code, perhaps as well as "from datetime >> import datetime". > > The first statement will import the datetime module and bind it to the > name "datetime" in the current namespace. The second will import the > datetime class from the datetime module and bind it to the name > "datetime" in thye current namespace, _in this cas overwriting the > first binding. IOW : you either use the first form and access the > datetime class as "datetime.datetime", or use the second form and > access the datetime class as "datetime", but using both forms is at > once useless and confusing. > > As far as I'm concerned, I strongly favor the first form (importing > the module and using the fully qualified name), since there are other > useful stuff in the datetime module and chances are you'll need them > if you need the (badly named) datetime.datetime class. > What I was trying to say is that he probably has code like this in (eg) app.views: from datetime import datetime from app.models import * and therefore thinks that he is using the datetime class, not the module. However, if app.models doesn't specify the symbols it exports, and has this in it: import datetime then the variable 'datetime' in app.views will be bound to the module, not the class. A similar bug is importing twice in the same file: from datetime import datetime import datetime Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Error: 'module' object is not callable
On Apr 27, 2:30 pm, Tom Evanswrote: > > The datetime class lives inside the datetime module. So far so good but! > You must have > "import datetime" in that code, perhaps as well as "from datetime > import datetime". The first statement will import the datetime module and bind it to the name "datetime" in the current namespace. The second will import the datetime class from the datetime module and bind it to the name "datetime" in thye current namespace, _in this cas overwriting the first binding. IOW : you either use the first form and access the datetime class as "datetime.datetime", or use the second form and access the datetime class as "datetime", but using both forms is at once useless and confusing. As far as I'm concerned, I strongly favor the first form (importing the module and using the fully qualified name), since there are other useful stuff in the datetime module and chances are you'll need them if you need the (badly named) datetime.datetime class. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Error: 'module' object is not callable
On Fri, Apr 27, 2012 at 6:46 AM, Gopi Kirupanithi <kgopia...@gmail.com> wrote: > Actually I am using datetime object for comparing two date inputs. > > if datetime(fromdtpart[2],fromdtpart[1],fromdtpart[0]) < > datetime(todtpart[2], todtpart[1], todtpart[0]): > > while execute the above line, I got the " 'module' object is not > callable " error. > > > Anybody can explain why this error occur.. > The datetime class lives inside the datetime module. You must have "import datetime" in that code, perhaps as well as "from datetime import datetime". Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Error: 'module' object is not callable
How are you importing datetime? In python 2.7, import datetime datetime.datetime() is callable not datetime() by itself. On Fri, Apr 27, 2012 at 8:46 AM, Gopi Kirupanithi <kgopia...@gmail.com>wrote: > Actually I am using datetime object for comparing two date inputs. > > if datetime(fromdtpart[2],fromdtpart[1],fromdtpart[0]) < > datetime(todtpart[2], todtpart[1], todtpart[0]): > > while execute the above line, I got the " 'module' object is not > callable " error. > > > Anybody can explain why this error occur.. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Error: 'module' object is not callable
Actually I am using datetime object for comparing two date inputs. if datetime(fromdtpart[2],fromdtpart[1],fromdtpart[0]) < datetime(todtpart[2], todtpart[1], todtpart[0]): while execute the above line, I got the " 'module' object is not callable " error. Anybody can explain why this error occur.. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: TypeError: 'module' object is not callable
Is there any way to tell through debugging if there's an issue with saving a record? This form seems to work fine, but the record does not save. I'm lost as to why it's not committing. Any pointers on debug statements for this kind of issue? On Fri, Jun 19, 2009 at 4:32 PM, db_333 <pleu...@gmail.com> wrote: > > I wanted to later implement a login based on a user session, and I got > some guidance from pretty decent Django book on learning to build > websites with Django. However, I can see that I need to better > understand how the middleware APIs work before I jump ahead. > I appreciate your quick responses > > On Jun 19, 4:25 pm, Alex Gaynor <alex.gay...@gmail.com> wrote: > > On Fri, Jun 19, 2009 at 6:24 PM, db_333 <pleu...@gmail.com> wrote: > > > > > here's what I have for the Middleware: > > > > > MIDDLEWARE_CLASSES = ( > > >'django.middleware.common.CommonMiddleware', > > >'django.contrib.sessions.middleware.SessionMiddleware', > > >'django.contrib.auth.middleware.AuthenticationMiddleware', > > >'django.contrib.auth.models' > > > ) > > > I'm searching the APIs to see what I might be missing... any > > > pointers? > > > > > On Jun 19, 4:20 pm, Andy McKay <a...@clearwind.ca> wrote: > > > > On 19-Jun-09, at 3:38 PM, db_333 wrote: > > > > > > > File "/Library/Python/2.5/site-packages/django/core/handlers/ > > > > > wsgi.py", line 228, in __call__ > > > > > self.load_middleware() > > > > > File "/Library/Python/2.5/site-packages/django/core/handlers/ > > > > > base.py", line 47, in load_middleware > > > > >mw_instance = mw_class() > > > > > TypeError: 'module' object is not callable > > > > > [19/Jun/2009 14:09:22] "GET / HTTP/1.1" 500 644 > > > > > > But what Middleware do you have installed - whats the settings.py > > > > value for middleware? > > > > > > It looks like that might be problem, none of the above code. > > > > Why did you add 'django.contrib.auth.models' to your middleware? That's > > whats causing your issue, but what were you hoping to accomplish? > > > > Alex > > > > -- > > "I disapprove of what you say, but I will defend to the death your right > to > > say it." --Voltaire > > "The people's good is the highest law."--Cicero > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: TypeError: 'module' object is not callable
I wanted to later implement a login based on a user session, and I got some guidance from pretty decent Django book on learning to build websites with Django. However, I can see that I need to better understand how the middleware APIs work before I jump ahead. I appreciate your quick responses On Jun 19, 4:25 pm, Alex Gaynor <alex.gay...@gmail.com> wrote: > On Fri, Jun 19, 2009 at 6:24 PM, db_333 <pleu...@gmail.com> wrote: > > > here's what I have for the Middleware: > > > MIDDLEWARE_CLASSES = ( > > 'django.middleware.common.CommonMiddleware', > > 'django.contrib.sessions.middleware.SessionMiddleware', > > 'django.contrib.auth.middleware.AuthenticationMiddleware', > > 'django.contrib.auth.models' > > ) > > I'm searching the APIs to see what I might be missing... any > > pointers? > > > On Jun 19, 4:20 pm, Andy McKay <a...@clearwind.ca> wrote: > > > On 19-Jun-09, at 3:38 PM, db_333 wrote: > > > > > File "/Library/Python/2.5/site-packages/django/core/handlers/ > > > > wsgi.py", line 228, in __call__ > > > > self.load_middleware() > > > > File "/Library/Python/2.5/site-packages/django/core/handlers/ > > > > base.py", line 47, in load_middleware > > > > mw_instance = mw_class() > > > > TypeError: 'module' object is not callable > > > > [19/Jun/2009 14:09:22] "GET / HTTP/1.1" 500 644 > > > > But what Middleware do you have installed - whats the settings.py > > > value for middleware? > > > > It looks like that might be problem, none of the above code. > > Why did you add 'django.contrib.auth.models' to your middleware? That's > whats causing your issue, but what were you hoping to accomplish? > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: TypeError: 'module' object is not callable
On Fri, Jun 19, 2009 at 6:24 PM, db_333 <pleu...@gmail.com> wrote: > > here's what I have for the Middleware: > > MIDDLEWARE_CLASSES = ( >'django.middleware.common.CommonMiddleware', >'django.contrib.sessions.middleware.SessionMiddleware', >'django.contrib.auth.middleware.AuthenticationMiddleware', >'django.contrib.auth.models' > ) > I'm searching the APIs to see what I might be missing... any > pointers? > > On Jun 19, 4:20 pm, Andy McKay <a...@clearwind.ca> wrote: > > On 19-Jun-09, at 3:38 PM, db_333 wrote: > > > > > File "/Library/Python/2.5/site-packages/django/core/handlers/ > > > wsgi.py", line 228, in __call__ > > >self.load_middleware() > > > File "/Library/Python/2.5/site-packages/django/core/handlers/ > > > base.py", line 47, in load_middleware > > >mw_instance = mw_class() > > > TypeError: 'module' object is not callable > > > [19/Jun/2009 14:09:22] "GET / HTTP/1.1" 500 644 > > > > But what Middleware do you have installed - whats the settings.py > > value for middleware? > > > > It looks like that might be problem, none of the above code. > > > Why did you add 'django.contrib.auth.models' to your middleware? That's whats causing your issue, but what were you hoping to accomplish? Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: TypeError: 'module' object is not callable
here's what I have for the Middleware: MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.models' ) I'm searching the APIs to see what I might be missing... any pointers? On Jun 19, 4:20 pm, Andy McKay <a...@clearwind.ca> wrote: > On 19-Jun-09, at 3:38 PM, db_333 wrote: > > > File "/Library/Python/2.5/site-packages/django/core/handlers/ > > wsgi.py", line 228, in __call__ > > self.load_middleware() > > File "/Library/Python/2.5/site-packages/django/core/handlers/ > > base.py", line 47, in load_middleware > > mw_instance = mw_class() > > TypeError: 'module' object is not callable > > [19/Jun/2009 14:09:22] "GET / HTTP/1.1" 500 644 > > But what Middleware do you have installed - whats the settings.py > value for middleware? > > It looks like that might be problem, none of the above code. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: TypeError: 'module' object is not callable
On 19-Jun-09, at 3:38 PM, db_333 wrote: > File "/Library/Python/2.5/site-packages/django/core/handlers/ > wsgi.py", line 228, in __call__ >self.load_middleware() > File "/Library/Python/2.5/site-packages/django/core/handlers/ > base.py", line 47, in load_middleware >mw_instance = mw_class() > TypeError: 'module' object is not callable > [19/Jun/2009 14:09:22] "GET / HTTP/1.1" 500 644 But what Middleware do you have installed - whats the settings.py value for middleware? It looks like that might be problem, none of the above code. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: TypeError: 'module' object is not callable
On Fri, Jun 19, 2009 at 5:38 PM, db_333 <pleu...@gmail.com> wrote: > > Hi, > > I am new to Django and am trying to create a simple form around an > existing database (I'm using 1.0). The Model I have looks like this: > > class Units(models.Model): >serial_number = models.CharField(max_length=25, primary_key=True) >build = models.CharField(max_length=50, blank=True) >model = models.CharField(max_length=20, blank=True) >create_date = models.DateField(null=True, blank=True) >source = models.CharField(max_length=20, blank=True) >class Meta: >db_table = u'units' > > In my view, I created this function: > def save_unit(request): >if request.method == 'POST': >form = UnitFormSave(request.POST) >if form.is_valid(): >unit = Units.objects.create( >serial_number = form.clean_data['serial_number'], >build = form.clean_data['build'], >model = form.clean_data['model'], >source = form.clean_data['source']) >unit.save(force_insert=True) >return HttpResponseRedirect('/search/') >else: >form = UnitFormSave() > >variables = RequestContext(request, { >'form': form >}) >return render_to_response('unit_save.html', variables) > > The form: > class UnitFormSave(forms.Form): >serial_number = forms.CharField(max_length=50) >build = forms.CharField(max_length=50) >model = forms.CharField(max_length=10) >source = forms.CharField(max_length=10) > > Unfortunately I getting this error and can't seem to get any detail > from some of the debugging. I know the answer is probably right in > front of me, but I can't see where I went wrong. I'm getting this > error from the server output: > > Traceback (most recent call last): > File "/Library/Python/2.5/site-packages/django/core/servers/ > basehttp.py", line 278, in run >self.result = application(self.environ, self.start_response) > File "/Library/Python/2.5/site-packages/django/core/servers/ > basehttp.py", line 635, in __call__ >return self.application(environ, start_response) > File "/Library/Python/2.5/site-packages/django/core/handlers/ > wsgi.py", line 228, in __call__ >self.load_middleware() > File "/Library/Python/2.5/site-packages/django/core/handlers/ > base.py", line 47, in load_middleware >mw_instance = mw_class() > TypeError: 'module' object is not callable > [19/Jun/2009 14:09:22] "GET / HTTP/1.1" 500 644 > > > > The issue is with something in your middleware, specifically you have something in your MIDDLEWARE setting that doesn't point to an actual class. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
TypeError: 'module' object is not callable
Hi, I am new to Django and am trying to create a simple form around an existing database (I'm using 1.0). The Model I have looks like this: class Units(models.Model): serial_number = models.CharField(max_length=25, primary_key=True) build = models.CharField(max_length=50, blank=True) model = models.CharField(max_length=20, blank=True) create_date = models.DateField(null=True, blank=True) source = models.CharField(max_length=20, blank=True) class Meta: db_table = u'units' In my view, I created this function: def save_unit(request): if request.method == 'POST': form = UnitFormSave(request.POST) if form.is_valid(): unit = Units.objects.create( serial_number = form.clean_data['serial_number'], build = form.clean_data['build'], model = form.clean_data['model'], source = form.clean_data['source']) unit.save(force_insert=True) return HttpResponseRedirect('/search/') else: form = UnitFormSave() variables = RequestContext(request, { 'form': form }) return render_to_response('unit_save.html', variables) The form: class UnitFormSave(forms.Form): serial_number = forms.CharField(max_length=50) build = forms.CharField(max_length=50) model = forms.CharField(max_length=10) source = forms.CharField(max_length=10) Unfortunately I getting this error and can't seem to get any detail from some of the debugging. I know the answer is probably right in front of me, but I can't see where I went wrong. I'm getting this error from the server output: Traceback (most recent call last): File "/Library/Python/2.5/site-packages/django/core/servers/ basehttp.py", line 278, in run self.result = application(self.environ, self.start_response) File "/Library/Python/2.5/site-packages/django/core/servers/ basehttp.py", line 635, in __call__ return self.application(environ, start_response) File "/Library/Python/2.5/site-packages/django/core/handlers/ wsgi.py", line 228, in __call__ self.load_middleware() File "/Library/Python/2.5/site-packages/django/core/handlers/ base.py", line 47, in load_middleware mw_instance = mw_class() TypeError: 'module' object is not callable [19/Jun/2009 14:09:22] "GET / HTTP/1.1" 500 644 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: 'module' object is not callable
I am really sorry for the stupid question Import Contex whit the C (the doc is right) all work like a charm Thanks On 10/1/06, Brett Parker <[EMAIL PROTECTED]> wrote: > > On Sun, Oct 01, 2006 at 11:20:08AM +0200, Marco Amato wrote: > > def index(request): > >list = Evento.objects.all().order_by('-data')[:5] > >t = loader.get_template('index.html') > >>c = context({'list': list,}) > >return HttpResponse(t.render(c)) > > > > I'm not sure what you've got imported, but the Context should have a > C... from my views I have: > > from django.template import Context, loader > > Cheers, > -- > Brett Parker --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
'module' object is not callable
I doesnt undestand this error : Type error at / 'module' object is not callable Request Method: GET Request URL: http://127.0.0.1:8000/ Exception Type: TypeError Exception Value: 'module' object is not callable Exception Location: /home/marco/test_/test../test/selecto/views.py in index, line 18 but the line 18 .. is : def index(request): list = Evento.objects.all().order_by('-data')[:5] t = loader.get_template('index.html') >c = context({'list': list,}) return HttpResponse(t.render(c)) ps: in the tutorial contex is writed Contex whit the C thanks MA. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---