问题
I've scoured the web for a solution but nothing seems to work. I'm getting the error:
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);
Within my project directory, I have my context_processor.py and init.py files (both not in a folder), however, it doesn't seem to find those files. If I want to avoid using hard-coded URLs, is this way viable or could someone suggest something otherwise? Any help is greatly appreciated!
回答1:
The outer project directory is not usually on the Python path. You probably just need context_processors.base_url
, without the mysite
.
回答2:
in my Settings I have:
from django.conf import global_settings
TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
...
'<appname>.context_processors.base_url',
...
)
来源:https://stackoverflow.com/questions/25437055/django-no-module-named-context-processors-base-url