Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Why do I get an error importing current_datetime? [RSS Feed]

#1 June 14, 2010 00:52:28

J.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Why do I get an error importing current_datetime?


I have enter the code in correctly,
views.py:

from django.http import HttpResponse
import datetime

def current_datetime(request):
now = datetime.datetime.now()
html = "<html><body>It is now %s.</body></html>" % now
return HttpResponse(html)
urls.py:

from django.conf.urls.defaults import *
from mysite.views import current_datetime



# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
('^time/$', current_datetime),


# Example:
# (r'^mysite/', include('mysite.foo.urls')),

# Uncomment the admin/doc line below and add
'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation:
(r'^admin/doc/', include('django.contrib.admindocs.')),

# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),
)

I continue to recieve this error:
cannot import name current_datetime

Please help me solve this problem because I cannot continue until I do.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 June 14, 2010 01:06:30

David E.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Why do I get an error importing current_datetime?


In your urls.py try doing a straight import instead of the from module
import function version:

import mysite.views

urlpatterns = patterns('',
('^time/$', mysite.views.current_datetime),


...doesn't seem like it should make a difference, but it's worth a shot...


On Sun, Jun 13, 2010 at 4:52 PM, JRMAbock <joshua.matl...@comcast.net>wrote:

> I have enter the code in correctly,
> views.py:
>
> from django.http import HttpResponse
> import datetime
>
> def current_datetime(request):
> now = datetime.datetime.now()
> html = "<html><body>It is now %s.</body></html>" % now
> return HttpResponse(html)
> urls.py:
>
> from django.conf.urls.defaults import *
> from mysite.views import current_datetime
>
>
>
> # Uncomment the next two lines to enable the admin:
> from django.contrib import admin
> admin.autodiscover()
>
> urlpatterns = patterns('',
> ('^time/$', current_datetime),
>
>
> # Example:
> # (r'^mysite/', include('mysite.foo.urls')),
>
> # Uncomment the admin/doc line below and add
> 'django.contrib.admindocs'
> # to INSTALLED_APPS to enable admin documentation:
> (r'^admin/doc/', include('django.contrib.admindocs.')),
>
> # Uncomment the next line to enable the admin:
> (r'^admin/', include(admin.site.urls)),
> )
>
> I continue to recieve this error:
> cannot import name current_datetime
>
> Please help me solve this problem because I cannot continue until I do.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@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-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 June 14, 2010 01:10:10

David E.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Why do I get an error importing current_datetime?


Or you may not even need the mysite part of the import:

import views

urlpatterns = patterns('',
('^time/$', views.current_datetime),



On Sun, Jun 13, 2010 at 5:06 PM, David Escobar <davidesco...@ieee.org>wrote:

> In your urls.py try doing a straight import instead of the from module
> import function version:
>
> import mysite.views
>
> urlpatterns = patterns('',
> ('^time/$', mysite.views.current_datetime),
>
>
> ...doesn't seem like it should make a difference, but it's worth a shot...
>
>
> On Sun, Jun 13, 2010 at 4:52 PM, JRMAbock <joshua.matl...@comcast.net>wrote:
>
>> I have enter the code in correctly,
>> views.py:
>>
>> from django.http import HttpResponse
>> import datetime
>>
>> def current_datetime(request):
>> now = datetime.datetime.now()
>> html = "<html><body>It is now %s.</body></html>" % now
>> return HttpResponse(html)
>> urls.py:
>>
>> from django.conf.urls.defaults import *
>> from mysite.views import current_datetime
>>
>>
>>
>> # Uncomment the next two lines to enable the admin:
>> from django.contrib import admin
>> admin.autodiscover()
>>
>> urlpatterns = patterns('',
>> ('^time/$', current_datetime),
>>
>>
>> # Example:
>> # (r'^mysite/', include('mysite.foo.urls')),
>>
>> # Uncomment the admin/doc line below and add
>> 'django.contrib.admindocs'
>> # to INSTALLED_APPS to enable admin documentation:
>> (r'^admin/doc/', include('django.contrib.admindocs.')),
>>
>> # Uncomment the next line to enable the admin:
>> (r'^admin/', include(admin.site.urls)),
>> )
>>
>> I continue to recieve this error:
>> cannot import name current_datetime
>>
>> Please help me solve this problem because I cannot continue until I do.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@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-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#4 June 14, 2010 02:06:14

J.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Why do I get an error importing current_datetime?


if i do that i get this error

'module' object has no attribute 'current_datetime'


On Jun 13, 8:10 pm, David Escobar <davidesco...@ieee.org> wrote:
> Or you may not even need the mysite part of the import:
>
> import views
>
> urlpatterns = patterns('',
>    ('^time/$', views.current_datetime),
>
> On Sun, Jun 13, 2010 at 5:06 PM, David Escobar <davidesco...@ieee.org>wrote:
>
>
>
> > In your urls.py try doing a straight import instead of the from module
> > import function version:
>
> > import mysite.views
>
> > urlpatterns = patterns('',
> >    ('^time/$', mysite.views.current_datetime),
>
> > ...doesn't seem like it should make a difference, but it's worth a shot...
>
> > On Sun, Jun 13, 2010 at 4:52 PM, JRMAbock <joshua.matl...@comcast.net>wrote:
>
> >> I have enter the code in correctly,
> >> views.py:
>
> >> from django.http import HttpResponse
> >> import datetime
>
> >> def current_datetime(request):
> >>    now = datetime.datetime.now()
> >>        html = "<html><body>It is now %s.</body></html>" % now
> >>        return HttpResponse(html)
> >> urls.py:
>
> >> from django.conf.urls.defaults import *
> >> from mysite.views import current_datetime
>
> >> # Uncomment the next two lines to enable the admin:
> >> from django.contrib import admin
> >> admin.autodiscover()
>
> >> urlpatterns = patterns('',
> >>    ('^time/$', current_datetime),
>
> >>    # Example:
> >>    # (r'^mysite/', include('mysite.foo.urls')),
>
> >>    # Uncomment the admin/doc line below and add
> >> 'django.contrib.admindocs'
> >>    # to INSTALLED_APPS to enable admin documentation:
> >>    (r'^admin/doc/', include('django.contrib.admindocs.')),
>
> >>    # Uncomment the next line to enable the admin:
> >>    (r'^admin/', include(admin.site.urls)),
> >> )
>
> >> I continue to recieve this error:
> >> cannot import name current_datetime
>
> >> Please help me solve this problem because I cannot continue until I do.
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "Django users" group.
> >> To post to this group, send email to django-us...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@google­groups.com>
> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/group/django-users?hl=en.-Hide quoted text -
>
> - Show quoted text -

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#5 June 14, 2010 05:11:38

Karen T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Why do I get an error importing current_datetime?


On Sun, Jun 13, 2010 at 9:06 PM, JRMAbock <joshua.matl...@comcast.net>wrote:

> if i do that i get this error
>
> 'module' object has no attribute 'current_datetime'
>


So the Python interpreter cannot find current_datetime defined in your views
module. The code you showed for it also would have caused Python to report a
indentation error (unexpected indent) on the line "html = "<html><body>..."
-- this line, as shown, was indented farther than the preceding line, and
Python would not accept that. So the code you have shown somehow isn't being
seen by the Python interpreter....

Karen
--http://tracey.org/kmt/--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#6 June 14, 2010 17:31:39

J.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Why do I get an error importing current_datetime?


Traceback:
File "C:\Python26\lib\site-packages\django\core\handlers\base.py" in
get_response
91. request.path_info)
File "C:\Python26\lib\site-packages\django\core\urlresolvers.py" in
resolve
214. for pattern in self.url_patterns:
File "C:\Python26\lib\site-packages\django\core\urlresolvers.py" in
_get_url_patterns
243. patterns = getattr(self.urlconf_module, "urlpatterns",
self.urlconf_module)
File "C:\Python26\lib\site-packages\django\core\urlresolvers.py" in
_get_urlconf_module
238. self._urlconf_module =
import_module(self.urlconf_name)
File "C:\Python26\lib\site-packages\django\utils\importlib.py" in
import_module
35. __import__(name)
File "C:\Users\Josh\Django-1.2.1\django\bin\mysite\..\mysite\urls.py"
in <module>
2. from mysite.views import current_datetime

Exception Type: ImportError at /time/
Exception Value: cannot import name current_datetime


this is the traceback i get........when the code is correct

let me just say that my python26 directory is:
C: Python26/lib/site-packages
and my Django-1.2.1 directory is:
C:user/Josh/Django-1.2.1

is this the problem, if so how should I fix this?

On Jun 14, 12:11 am, Karen Tracey <kmtra...@gmail.com> wrote:
> On Sun, Jun 13, 2010 at 9:06 PM, JRMAbock <joshua.matl...@comcast.net>wrote:
>
> > if i do that i get this error
>
> > 'module' object has no attribute 'current_datetime'
>
> So the Python interpreter cannot find current_datetime defined in your views
> module. The code you showed for it also would have caused Python to report a
> indentation error (unexpected indent) on the line "html = "<html><body>..."
> -- this line, as shown, was indented farther than the preceding line, and
> Python would not accept that. So the code you have shown somehow isn't being
> seen by the Python interpreter....
>
> Karen
> --http://tracey.org/kmt/--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#7 June 14, 2010 17:58:00

Karen T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Why do I get an error importing current_datetime?


On Mon, Jun 14, 2010 at 12:31 PM, JRMAbock <joshua.matl...@comcast.net>wrote:

> Traceback:
> File "C:\Python26\lib\site-packages\django\core\handlers\base.py" in
> get_response
> 91. request.path_info)
> File "C:\Python26\lib\site-packages\django\core\urlresolvers.py" in
> resolve
> 214. for pattern in self.url_patterns:
> File "C:\Python26\lib\site-packages\django\core\urlresolvers.py" in
> _get_url_patterns
> 243. patterns = getattr(self.urlconf_module, "urlpatterns",
> self.urlconf_module)
> File "C:\Python26\lib\site-packages\django\core\urlresolvers.py" in
> _get_urlconf_module
> 238. self._urlconf_module =
> import_module(self.urlconf_name)
> File "C:\Python26\lib\site-packages\django\utils\importlib.py" in
> import_module
> 35. __import__(name)
> File "C:\Users\Josh\Django-1.2.1\django\bin\mysite\..\mysite\urls.py"
> in <module>
> 2. from mysite.views import current_datetime
>
> Exception Type: ImportError at /time/
> Exception Value: cannot import name current_datetime
>
>
> this is the traceback i get........when the code is correct
>
> let me just say that my python26 directory is:
> C: Python26/lib/site-packages
> and my Django-1.2.1 directory is:
> C:user/Josh/Django-1.2.1
>
> is this the problem, if so how should I fix this?
>

The Python interpreter is reporting that it cannot find anything named
current_datetime in the mysite.views module. Somehow what you think is in
the mysite views.py file is not what Python is finding. The code you showed
previously in the thread had an indentation error, so certainly what you
showed earlier is not being found by Python. Possibly the indentation
problems are more extensive than could be seen in what you posted, and
current_datetime in views.py is placed in some way (with some indentation)
that is making it entirely invisible to Python. You need to double and
triple check that what you have put in views.py is indented properly (the
def of the function should not be indented at all, it mut not be nested
inside any other function definition, and the function body itself needs to
be consistently indented).

Karen
--http://tracey.org/kmt/--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#8 June 14, 2010 18:14:18

J.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Why do I get an error importing current_datetime?


from django.http import HttpResponse
import datetime

def current_datetime(request):
now = datetime.datetime.now()
html = "<html><body>It is now %s.</body></html>" % now
return HttpResponse(html)

this is what it looks like....its exactly how they tell me to show
it....Python located my hello module before so I cant understand why
this is not working...The code is absolutely correct and python is
able to read otehr modules except tusing datetime. although in the
python shell datetime works.

On Jun 14, 12:57 pm, Karen Tracey <kmtra...@gmail.com> wrote:
> On Mon, Jun 14, 2010 at 12:31 PM, JRMAbock <joshua.matl...@comcast.net>wrote:
>
>
>
>
>
> > Traceback:
> > File "C:\Python26\lib\site-packages\django\core\handlers\base.py" in
> > get_response
> >  91.                         request.path_info)
> > File "C:\Python26\lib\site-packages\django\core\urlresolvers.py" in
> > resolve
> >  214.             for pattern in self.url_patterns:
> > File "C:\Python26\lib\site-packages\django\core\urlresolvers.py" in
> > _get_url_patterns
> >  243.         patterns = getattr(self.urlconf_module, "urlpatterns",
> > self.urlconf_module)
> > File "C:\Python26\lib\site-packages\django\core\urlresolvers.py" in
> > _get_urlconf_module
> >  238.             self._urlconf_module =
> > import_module(self.urlconf_name)
> > File "C:\Python26\lib\site-packages\django\utils\importlib.py" in
> > import_module
> >  35.     __import__(name)
> > File "C:\Users\Josh\Django-1.2.1\django\bin\mysite\..\mysite\urls.py"
> > in <module>
> >  2. from mysite.views import current_datetime
>
> > Exception Type: ImportError at /time/
> > Exception Value: cannot import name current_datetime
>
> > this is the traceback i get........when the code is correct
>
> > let me just say that my python26 directory is:
> > C: Python26/lib/site-packages
> > and my Django-1.2.1 directory is:
> > C:user/Josh/Django-1.2.1
>
> > is this the problem, if so how should I fix this?
>
> The Python interpreter is reporting that it cannot find anything named
> current_datetime in the mysite.views module. Somehow what you think is in
> the mysite views.py file is not what Python is finding. The code you showed
> previously in the thread had an indentation error, so certainly what you
> showed earlier is not being found by Python. Possibly the indentation
> problems are more extensive than could be seen in what you posted, and
> current_datetime in views.py is placed in some way (with some indentation)
> that is making it entirely invisible to Python. You need to double and
> triple check that what you have put in views.py is indented properly (the
> def of the function should not be indented at all, it mut not be nested
> inside any other function definition, and the function body itself needs to
> be consistently indented).
>
> Karen
> --http://tracey.org/kmt/-Hide quoted text -
>
> - Show quoted text -

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#9 June 14, 2010 18:39:53

Karen T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Why do I get an error importing current_datetime?


On Mon, Jun 14, 2010 at 1:14 PM, JRMAbock <joshua.matl...@comcast.net>wrote:

> from django.http import HttpResponse
> import datetime
>
> def current_datetime(request):
> now = datetime.datetime.now()
> html = "<html><body>It is now %s.</body></html>" % now
> return HttpResponse(html)
>
> this is what it looks like....its exactly how they tell me to show
> it....Python located my hello module before so I cant understand why
> this is not working...The code is absolutely correct and python is
> able to read otehr modules except tusing datetime. although in the
> python shell datetime works.
>
>
That code now looks to be properly indented. However, the Python interpreter
is still isn't finding it. From the traceback Python is finding your
mysite/urls.py file at:

C:\Users\Josh\Django-1.2.1\django\bin\mysite\..\mysite\urls.py

Is the file you are editing for views.py:

C:\Users\Josh\Django-1.2.1\django\bin\views.py

?

or is there a views.py file somewhere else? Possibly you are editing one
file and Python is finding another.

Note putting your mysite directory under django\bin seems a bit odd.
Ordinarily you would have your project directory somewhere entirely outside
of the django tree, like c:\Users\Josh\mysite, for example.

Karen
--http://tracey.org/kmt/--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#10 June 14, 2010 18:40:58

Karen T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Why do I get an error importing current_datetime?


On Mon, Jun 14, 2010 at 1:39 PM, Karen Tracey <kmtra...@gmail.com> wrote:

> C:\Users\Josh\Django-1.2.1\django\bin\views.py
>

This should have been

C:\Users\Josh\Django-1.2.1\django\bin\mysite\views.py

in the previous mail.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » Why do I get an error importing current_datetime? [RSS Feed]

Board footer

Moderator control

Enjoy the 20th of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support