Django:没有名为context_processors的模块,基本URL

时间:2014-08-21 22:39:12

标签: python django django-templates django-settings base-url

我已经在网上搜索解决方案,但似乎没有任何效果。我收到了错误:

ImproperlyConfigured at /tool/page4/

Error importing module mysite.context_processors: "No module named context_processors"

settings.py

TEMPLATE_CONTEXT_PROCESSORS = (
# default context processors for Django 1.4
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.core.context_processors.tz",
"django.contrib.messages.context_processors.messages",
"django.core.context_processors.request",
"mysite.context_processors.baseurl",
)

views.py

if(team_value != "---------" && product_value != "---------" && type_team.length > 3 && pattern_value.length > 1)
      {
        $.ajax({

              url: {{BASE_URL}}'/tool/page4/add_team/',
              type: 'POST',
              dataType: 'html',
              data: {
                  "team" : team_value,
                  "product" : product_value,
                  "pattern" : pattern_value,
                  "type" : type_team,
                  "array" : data_array
              },
              async: false,

              error: function(XMLHttpRequest, textStatus, errorThrown) { 
                  alert("Status: " + textStatus); alert("Error: " + errorThrown); 
              } 
          });
        location.reload(true);

在我的项目目录中,我有我的context_processor.py和 init .py文件(两者都不在文件夹中),但是,它似乎找不到这些文件。如果我想避免使用硬编码的URL,这种方式是可行的还是有人可以提出建议?任何帮助是极大的赞赏!

2 个答案:

答案 0 :(得分:5)

外部项目目录通常不在Python路径上。您可能只需要context_processors.base_url,而不需要mysite

答案 1 :(得分:0)

在我的设置中我有:

from django.conf import global_settings

TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
...
'<appname>.context_processors.base_url',
...

)