2

助けが必要だということがありました。私のdjangoアプリケーションには、次のコードがあります:

from django.template import Context

render_dict = {'scan': oval_scan, 'user': user, 'vulns': oval_vulns, 'asset_vulns': asset_vulns}
report_html = get_template('oval_report.html').render(Context(render_dict))

ただし、djangoは次のエラーを出しました:

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 111, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/home/nopsec/nopsecvrm/apps/pegasus/views.py", line 2359, in ovalReport
    report_html = get_template('pegasus/oval_report.html').render(Context(render_dict))
  File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 121, in render
    context.render_context.push()
AttributeError: 'Context' object has no attribute 'render_context'

間違って使用された別のインポートパッケージに別の場所があるため、このエラーに一度遭遇したことを思い出したContextので、コードを次のように変更します(非常に醜いですが動作します):

import django

render_dict = {'scan': oval_scan, 'user': user, 'vulns': oval_vulns, 'asset_vulns': asset_vulns}
report_html = get_template('report.html').render(django.template.Context(render_dict))

Context私の質問は次のとおりです。トレースバックエラーを見て、djangoが誤って使用したものをどのように判断できますか? どうすればこの状況を解決できますか? ありがとう。

4

2 に答える 2

0

モジュールの__import__関数を使用します。__builtins__

#Detecting name conflicts:
module_name_as_string = 'mymodule'

if module_name_as_string in globals(): #we have name collision
   try:
      custom_module = __import__(module_name_as_string)
   except ImportError:
      pass
于 2013-04-18T15:40:29.227 に答える