urls.py?
I am trying to learning django by working my way through The Definitive Guide to django (vers 1.1). I am running django 1.1.1 on Ubuntu 10.04. I get the following error when trying to import urls: >>> import urls Traceback (most recent call last): File "", line 1, in File "/home/jfb/MyProgs/djcode/mysite/urls.py", line 16, in (r'^contact/$',views.contact), AttributeError: 'module' object has no attribute 'contact' Here is urls.py: from django.conf.urls.defaults import * from mysite import views from mysite.views import hello, current_datetime, hours_ahead, display_meta from django.contrib import admin from mysite.contact import views from mysite.books import views admin.autodiscover() urlpatterns = patterns('', (r'^hello/$', hello), (r'^time/$', current_datetime), (r'^time/plus/(\d{1,2})/$', hours_ahead), (r'^admin/' , include(admin.site.urls)), (r'^contact/$',views.contact), (r'^search-form/$', views.search_form), #from mysite.books (r'^search/$', views.search), # from mysite.books ) If I comment out either the reference to importing contact and it's pattern or books and it's pattern I get no error. Both books and contact are directories at the same level under mysite. Usually when I get in situations like this it is because I missed something. I've gone back a reviewed everything I have done and still don't understand what is wrong. I would appreciate any help you could give me in figuring this out. Thanks, Jim -- 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: urls.py?
On 12/08/2011 07:23 PM, Mario Gudelj wrote: I think you have to add "from views import *" to urls.py and make sure you have a method called contact in your view. Cheers, Thanks, but I added "from views import *" and there definitely is a method called contact in /mysite/contact and still get the error. Regards, Jim On 09/12/2011 12:10 PM, "Jim Byrnes" wrote: I am trying to learning django by working my way through The Definitive Guide to django (vers 1.1). I am running django 1.1.1 on Ubuntu 10.04. I get the following error when trying to import urls: import urls Traceback (most recent call last): File "", line 1, in File "/home/jfb/MyProgs/djcode/**mysite/urls.py", line 16, in (r'^contact/$',views.contact), AttributeError: 'module' object has no attribute 'contact' Here is urls.py: from django.conf.urls.defaults import * from mysite import views from mysite.views import hello, current_datetime, hours_ahead, display_meta from django.contrib import admin from mysite.contact import views from mysite.books import views admin.autodiscover() urlpatterns = patterns('', (r'^hello/$', hello), (r'^time/$', current_datetime), (r'^time/plus/(\d{1,2})/$', hours_ahead), (r'^admin/' , include(admin.site.urls)), (r'^contact/$',views.contact), (r'^search-form/$', views.search_form), #from mysite.books (r'^search/$', views.search), # from mysite.books ) If I comment out either the reference to importing contact and it's pattern or books and it's pattern I get no error. Both books and contact are directories at the same level under mysite. Usually when I get in situations like this it is because I missed something. I've gone back a reviewed everything I have done and still don't understand what is wrong. I would appreciate any help you could give me in figuring this out. Thanks, Jim -- 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+unsubscribe@** googlegroups.com. For more options, visit this group at http://groups.google.com/** group/django-users?hl=en<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.
Re: urls.py?
On 12/09/2011 03:06 AM, Reinout van Rees wrote: On 09-12-11 01:28, Jim Byrnes wrote: from django.conf.urls.defaults import * from mysite import views from mysite.views import hello, current_datetime, hours_ahead, display_meta from django.contrib import admin from mysite.contact import views from mysite.books import views admin.autodiscover() urlpatterns = patterns('', (r'^hello/$', hello), (r'^time/$', current_datetime), (r'^time/plus/(\d{1,2})/$', hours_ahead), (r'^admin/' , include(admin.site.urls)), (r'^contact/$',views.contact), (r'^search-form/$', views.search_form), #from mysite.books (r'^search/$', views.search), # from mysite.books ) mysite.contact.views might very well have a contact() method, but mysite.books.views probably does not. And you're importing 'views' a couple of times at the top. The last "from mysite.books import views" is winning :-) You cannot have one variable point to several things at the same time. Best thing you can do: import mysite.contact.views import mysite.books.views ... (r'^contact/$', mysite.contact.views.contact), Reinout That worked and your explanation gave me a better understanding of how the process works. Thanks, Jim -- 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.