Django non-recurring error: 'module' object has no 'validators' attributes

I am using Django 0.97 pre (yes my site is still not updated to be trunk compatible). I am using apache + fastcgi for this. And I have a weird problem: sometimes (I can't guess the order) some of the views throw an error like this:

Tried audio_index in module mysite.audio.views. Error was: 'module' object has no attribute 'validators'

      

There are no validators in this view:

def audio_index(request, language):
audio_list = AudioFile.objects.all().filter(lang = language).order_by('-title')
audio_list = list(audio_list)[:10]
sections_list = AudioCategory.objects.all().filter(lang = language)  
template_name = 'audio/index_' + language + '.html'
t = loader.get_template(template_name)
c = Context({
    'sections_list': sections_list,
    'lang': language,
    'audio_list': audio_list,
    'len1': len(audio_list),
    'menu_item': 'audio', 
})
return HttpResponse(t.render(c))

      

The most interesting fact is that if I reload this page after a while, it will load absolutely correctly (I do not change any code or data in the database before it). Do you have any idea what this is? Perhaps this is a non-django (apache? Db?) Problem?

The complete stacktrace command looks like this:

Traceback:
File "/home/shal_prod/django/django_src/django/core/handlers/base.py" in get_response
  73.             callback, callback_args, callback_kwargs = resolver.resolve(request.path)
File "/home/shal_prod/django/django_src/django/core/urlresolvers.py" in resolve
  233.                     sub_match = pattern.resolve(new_path)
File "/home/shal_prod/django/django_src/django/core/urlresolvers.py" in resolve
  172.             return self.callback, args, kwargs
File "/home/shal_prod/django/django_src/django/core/urlresolvers.py" in _get_callback
  184.             raise ViewDoesNotExist, "Tried %s in module %s. Error was: %s" % (func_name, mod_name, str(e))

Exception Type: ViewDoesNotExist at /ru/about/
Exception Value: Tried index in module mysite.about.views. Error was: 'module' object has no attribute 'validators'

      

+2


source to share


2 answers


I cannot answer your problem (except please post your model code as I suspect there is a problem), but can I point out that these two lines:

audio_list = AudioFile.objects.all().filter(lang = language).order_by('-title')
audio_list = list(audio_list)[:10]

      

terribly ineffective. What you are doing here is getting all the AudioFile objects, creating them, and then deleting all but 10. What you should be doing is simply:



audio_list = AudioFile.objects.all().filter(lang=language).order_by('-title')[:10]

      

so that Django slashes the queryset before evaluating it and only queries the database for 10 objects. You can always convert it to a list after slicing if you really need to.

+1


source


It is very difficult to debug without a stack trace from your application.

What the error message means is that one of your modules is expecting another module to contain a variable called "validators"

My guess is that you are assigning a global variable to that name in some method and then expecting it to be present in another method. Try to find keywords in your code and see where it is used.

edit: Based on the original stacktrace, it looks like the view that is handling the url is not being imported. It looks like the views use URL strings using names rather than module functions.



Try to navigate from this url ad template

urlpatterns = patterns('',
    (r'^admin/(.*)', 'admin.site.root'),

      

to this template

import admin.site
urlpatterns = patterns('',
    (r'^admin/(.*)', admin.site.root), #note string is gone here

      

0


source







All Articles