0

I have a django app with version 1.2.3 and updated to 1.6.5 and the app is working fine, but the admin url is not working and facing with the below error when i accessed localhost:8000/admin/

Traceback

Traceback:
File "/Users/user/.envs/proj/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  112.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/user/.envs/proj/lib/python2.7/site-packages/django/contrib/admin/sites.py" in wrapper
  215.                 return self.admin_view(view, cacheable)(*args, **kwargs)
File "/Users/user/.envs/proj/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  99.                     response = view_func(request, *args, **kwargs)
File "/Users/user/.envs/proj/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  52.         response = view_func(request, *args, **kwargs)
File "/Users/user/.envs/proj/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
  198.             return view(request, *args, **kwargs)
File "/Users/user/.envs/proj/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  52.         response = view_func(request, *args, **kwargs)
File "/Users/user/.envs/proj/lib/python2.7/site-packages/django/contrib/admin/sites.py" in index
  358.                             model_dict['admin_url'] = reverse('admin:%s_%s_changelist' % info, current_app=self.name)
File "/Users/user/.envs/proj/lib/python2.7/site-packages/django/core/urlresolvers.py" in reverse
  503.                 app_list = resolver.app_dict[ns]
File "/Users/user/.envs/proj/lib/python2.7/site-packages/django/core/urlresolvers.py" in app_dict
  329.             self._populate()
File "/Users/user/.envs/proj/lib/python2.7/site-packages/django/core/urlresolvers.py" in _populate
  290.                     for name in pattern.reverse_dict:
File "/Users/user/.envs/proj/lib/python2.7/site-packages/django/core/urlresolvers.py" in reverse_dict
  315.             self._populate()
File "/Users/user/.envs/proj/lib/python2.7/site-packages/django/core/urlresolvers.py" in _populate
  278.                     lookup_str = callback.__module__ + "." + callback.__name__

Exception Type: TypeError at /admin/
Exception Value: coercing to Unicode: need string or buffer, instancemethod found

And when i shifted the django version to 1.5.3 its working without error, so what wrong with the latest version, does we need to do any changes with unicode settings ?

Edit:

urls.py

from django.conf.urls import *
from django.conf import settings
from django.contrib import admin
from django.views.generic import TemplateView

from feeds.sitemap import SITEMAP

admin.autodiscover()

urlpatterns = patterns('',
  # Core Website Pages
  (r'^$', 'core.views.homepage'),
  # Site Map
  (r'^sitemap.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': SITEMAP}),
  # Admin pages
  (r'^admin/', include(admin.site.urls)),
  (r'^search/', include('search.urls')),
)
# Static Content Code, Used Only For Development
import os.path

static = os.path.join( 
  os.path.dirname(__file__), 'media'
)
new_static = os.path.join( 
  os.path.dirname(__file__), 'new_media'
)

if settings.DEBUG:
  urlpatterns += patterns('',
      (r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': static}),
      (r'^new_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': new_static}),
  )

search/urls.py

from django.conf.urls import *
from search.views import SiteSearch

urlpatterns = patterns('search.views',
    url(r'^$', SiteSearch(), name='site_search'),
)

search/views.py

from haystack.views import SearchView

class SiteSearch(SearchView):

    def get_results(self):
        model_search_form = self.form_class(self.request.GET)
        model_search_form.is_valid()
        models = model_search_form.get_models()
        if self.query:
            search_results = self.form.search()
            if len(models) == 1 and models[0].__name__ == 'Press_Releases':
                search_results = search_results.order_by('-date')
            return search_results

        return []
4

1 回答 1

2

您的异常是由较旧的 Django-Haystack 版本引起的。升级它,它与 Django 1.6 不兼容。

1.0 版中,至少该类SearchView定义__name__方法,这与 Python 中的正常使用相反,其中该属性是字符串。

于 2014-06-23T12:55:33.263 回答