2011-01-12 14 views
13

मुझे django में एक यूआरएल व्यू बनाने में समस्या है। यह मुझे इस त्रुटि देता है (FERROL एक अंतरिक्ष वस्तु है):django 'str' ऑब्जेक्ट कॉल करने योग्य नहीं है

रिक्त स्थान/models.py

class Space(models.Model): 

""" 
Basic spaces model. 
""" 
name = models.CharField(_('Name'), max_length=100, unique=True) 
description = models.TextField(_('Description')) 
date = models.DateTimeField(auto_now_add=True) 

logo = models.ImageField(upload_to='spaces/logos', 
         verbose_name=_('Logotype')) 
banner = models.ImageField(upload_to='spaces/banners', 
          verbose_name=_('Banner')) 

मुख्य urls.py

urlpatterns = patterns('', 

# Django administration 
(r'^admin/', include(admin.site.urls)), 

(r'^spaces/', include('apps.spaces.urls')), 

(r'^static/(?P<path>.*)$', 'django.views.static.serve', 
    {'document_root': 'static'}), 

) 

if 'e_cidadania.apps.rosetta' in settings.INSTALLED_APPS: 
urlpatterns += patterns('', 
    url(r'^rosetta/', include('apps.rosetta.urls')), 
) 
:

TypeError at /spaces/ferrol/ 
'str' object is not callable 
Request Method: GET 
Request URL: http://localhost:8000/spaces/ferrol/ 
Django Version: 1.2.3 
Exception Type: TypeError 
Exception Value:  
'str' object is not callable 
Exception Location: /usr/local/lib/python2.6/dist-packages/Django-1.2.3-py2.6.egg/django/core/handlers/base.py in get_response, line 100 

यहाँ कोड है

रिक्त स्थान/urls.py

urlpatterns = patterns('', 
    # Spaces 
    (r'^(?P<space_name>[-\w\./\s]+)/', 'view_space_index'), 
) 

रिक्त स्थान/views.py

def view_space_index(request, space_name): 

""" 
Show the index page for the requested space. 
""" 
place = get_object_or_404(Space, name=space_name) 

return object_detail(request, 
        queryset = Space.objects.all(), 
        object_id = place.id, 
        template_name = 'spaces/index.html', 
        template_object_name = 'get_place') 
+0

आपका मुख्य urls.py कैसा दिखता है? समस्या शायद वहां है। –

उत्तर

30

अपने खाली जगहों में/फ़ाइल urls.py आप विधि देखने के लिए पूरा पथ प्रदान करने के लिए है:

urlpatterns = patterns('', 
    # Spaces 
    (r'^(?P<space_name>[-\w\./\s]+)/', 'spaces.views.view_space_index'), 
) 

या इस तरह:

urlpatterns = patterns('spaces.views', 
    # Spaces 
    (r'^(?P<space_name>[-\w\./\s]+)/', 'view_space_index'), 
) 
+1

अब यह काम कर रहा है। मैं कार्यों को बुलाए जाने से पहले पैटर्न (apps.spaces.views) डालना भूल गया, मुझ पर शर्म की बात है! –

+1

@ ऑस्कर - अगर यह आपके प्रश्न का उत्तर देता है - क्या आप इसे स्वीकार्य मान सकते हैं? –

संबंधित मुद्दे