函数寻找3个参数但只给出2个参数。不确定问题出在哪里

问题描述 投票:0回答:1

当我尝试解析我的django项目中的链接时,我遇到了错误页面。它告诉我函数find_module()接受3个参数但只提供2个参数。现在我理解这意味着什么,但我找不到错误的起源。回溯指向一个视图,但我没有看到代码有任何问题。

这是追溯:

    Environment:


Request Method: GET
Request URL: https://0.0.0.0/ai_stats/dash/development/

Django Version: 1.3.1
Python Version: 2.7.5
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'django.contrib.admindocs',
 'apps.minisar',
 'apps.mock',
 'apps.actional',
 'apps.ai_stats',
 'apps.health',
 'apps.soap',
 'apps.directentry',
 'apps.toys',
 'apps.solutions']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/app/gaic/apps/ai_stats/views.py" in dashboard
  26.     return render_to_response('ai_stats/dashboard.html', locals())
File "/usr/lib/python2.7/site-packages/django/shortcuts/__init__.py" in render_to_response
  20.     return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/usr/lib/python2.7/site-packages/django/template/loader.py" in render_to_string
  181.         t = get_template(template_name)
File "/usr/lib/python2.7/site-packages/django/template/loader.py" in get_template
  157.     template, origin = find_template(template_name)
File "/usr/lib/python2.7/site-packages/django/template/loader.py" in find_template
  134.             source, display_name = loader(name, dirs)
File "/usr/lib/python2.7/site-packages/django/template/loader.py" in __call__
  42.         return self.load_template(template_name, template_dirs)
File "/usr/lib/python2.7/site-packages/django/template/loader.py" in load_template
  48.             template = get_template_from_string(source, origin, template_name)
File "/usr/lib/python2.7/site-packages/django/template/loader.py" in get_template_from_string
  168.     return Template(source, origin, name)
File "/usr/lib/python2.7/site-packages/django/template/base.py" in __init__
  108.         self.nodelist = compile_string(template_string, origin)
File "/usr/lib/python2.7/site-packages/django/template/base.py" in compile_string
  136.     return parser.parse()
File "/usr/lib/python2.7/site-packages/django/template/base.py" in parse
  239.                     compiled_result = compile_func(self, token)
File "/usr/lib/python2.7/site-packages/django/template/loader_tags.py" in do_extends
  214.     nodelist = parser.parse()
File "/usr/lib/python2.7/site-packages/django/template/base.py" in parse
  239.                     compiled_result = compile_func(self, token)
File "/usr/lib/python2.7/site-packages/django/template/defaulttags.py" in load
  1050.                 lib = get_library(taglib)
File "/usr/lib/python2.7/site-packages/django/template/base.py" in get_library
  1007.             lib = import_library(taglib_module)
File "/usr/lib/python2.7/site-packages/django/template/base.py" in import_library
  959.         if not module_has_submodule(app_module, taglib):
File "/usr/lib/python2.7/site-packages/django/utils/module_loading.py" in module_has_submodule
  15.         if finder.find_module(name):

Exception Type: TypeError at /ai_stats/dash/development/
Exception Value: find_module() takes exactly 3 arguments (2 given)

以及它引用的views.py文件:

from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse

import ai2

import logging
logging.basicConfig()
log = logging.getLogger(__name__)


def index(request):
    # ai2.refresh_cache()
    return render_to_response('ai_stats/index.html', locals())
    # return HttpResponseRedirect(reverse('apps.ai_stats.views.dashboard', kwargs={'env':ai2.PROD}))


def dashboard(request, env):
    ai2.refresh_cache()
    # env = ai2.PROD
    mf_error, mf_data, _ = ai2.AIStats().data_for_chart('most_failures', env=env)
    mc_error, mc_data, _ = ai2.AIStats().data_for_chart('most_calls', env=env)
    wp_error, wp_data, _ = ai2.AIStats().data_for_chart('worst_performing', env=env)
    error = (mf_error or '') + (mc_error or '') + (wp_error or '')
    cache_timestamp = ai2.data_cache['timestamp']
    return render_to_response('ai_stats/dashboard.html', locals())


def drill(request, env, chart):
    # env = ai2.PROD
    row_limit = int(request.GET.get('limit', 100))
    error, data, _ = ai2.AIStats().data_for_chart(chart, env=env, limit=row_limit)
    cache_timestamp = ai2.data_cache['timestamp']
    return render_to_response('ai_stats/drill_%s.html' % chart, locals())


def dash_data(request, env, chart):
    # env = ai2.PROD
    error, data, chart_type = ai2.AIStats().data_for_chart(chart, env=env, params=request.GET)
    r = render_to_response('ai_stats/%s.xml' % chart, locals())
    if chart_type == ai2.GRAPH_CHART:
        r['Content-Type'] = 'text/xml'
    return r


def pop(request, env, chart):
    pop_template = 'pop_mtd'
    if chart == 'all_mtd':
        pop_template = 'pop_all'
    ops_chart = '%s_ops' % chart
    return render_to_response('ai_stats/' + pop_template + '.html', locals())

和urls.py:

import os
from django.conf.urls.defaults import *
from django.conf import settings

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

urlpatterns = patterns('',
    url(r'^media/(?P<path>.*)$',  'django.views.static.serve', {'document_root': os.path.join(settings.DJANGO_PROJECT_ROOT, 'ai_stats/media')}),
    url(r'^$', 'apps.ai_stats.views.index', name='index'),
    url(r'^dash$', 'apps.ai_stats.views.index', name='index'),
    url(r'^dash/(?P<env>(production|certification|uat|integration|development))/$', 'apps.ai_stats.views.dashboard'),
    url(r'^dash/(?P<env>(production|certification|uat|integration|development))/drill/(?P<chart>[a-z_]+)/$', 'apps.ai_stats.views.drill'),
    url(r'^dash/(?P<env>(production|certification|uat|integration|development))/pop/(?P<chart>[a-z_]+)/$', 'apps.ai_stats.views.pop'),
    url(r'^dash/(?P<env>(production|certification|uat|integration|development))/(?P<chart>[a-z_]+)/$', 'apps.ai_stats.views.dash_data'),
python django
1个回答
1
投票

sys.meta_path有一个找不到方法签名的发现者。打开一个shell,迭代它以确定它是什么。这可能是一个用python 3而不是python 2编写的finder,它没有path的可选find_module参数。

您的问题的答案是卸载该软件包,或者(以及我建议的)将项目的依赖项(包括Django)更新到最新版本。以及碰到python 3(如果可以的话)。显然,这第二个选择会变得更加繁琐,但是当你坚持使用Django的非维护版本时,你只会遇到更多这些问题。

Python 3 find_module

Python 2 find_module

© www.soinside.com 2019 - 2024. All rights reserved.