我已经使用django 1.6和IIS7.5在Web服务器上部署了我的网站,它运行良好。
在我将env升级到django 1.8并更改我的代码之后,我通过'manage.py runserver'测试了我的网站,它也运行良好。
我正在使用Windows 8.1,我尝试在IIS 8.5上部署网站,但我发现它不起作用,错误报告非常奇怪。
当我访问返回json的网址时,它运行良好。
当我访问不存在的网址时,它返回了django 404页面。
当我访问普通页面网址时,错误报告如下所示。
Error occurred:
Traceback (most recent call last):
File "c:\python34\lib\site-packages\django\core\handlers\base.py", line 132, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\myFile\project\python\MOCS\index\views.py", line 22, in index
return render_to_response('base.html', content)
File "c:\python34\lib\site-packages\django\shortcuts\__init__.py", line 29, in render_to_response
return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "c:\python34\lib\site-packages\django\template\loader.py", line 98, in render_to_string
template = get_template(template_name, using=using)
File "c:\python34\lib\site-packages\django\template\loader.py", line 35, in get_template
return engine.get_template(template_name, dirs)
File "c:\python34\lib\site-packages\django\template\backends\django.py", line 30, in get_template
return Template(self.engine.get_template(template_name, dirs))
File "c:\python34\lib\site-packages\django\template\engine.py", line 167, in get_template
template, origin = self.find_template(template_name, dirs)
File "c:\python34\lib\site-packages\django\template\engine.py", line 141, in find_template
source, display_name = loader(name, dirs)
File "c:\python34\lib\site-packages\django\template\loaders\base.py", line 13, in __call__
return self.load_template(template_name, template_dirs)
File "c:\python34\lib\site-packages\django\template\loaders\base.py", line 23, in load_template
template = Template(source, origin, template_name, self.engine)
File "c:\python34\lib\site-packages\django\template\base.py", line 190, in __init__
self.nodelist = engine.compile_string(template_string, origin)
File "c:\python34\lib\site-packages\django\template\engine.py", line 261, in compile_string
return parser.parse()
File "c:\python34\lib\site-packages\django\template\base.py", line 341, in parse
compiled_result = compile_func(self, token)
File "c:\python34\lib\site-packages\django\template\defaulttags.py", line 1159, in load
lib = get_library(taglib)
File "c:\python34\lib\site-packages\django\template\base.py", line 1387, in get_library
templatetags_modules = get_templatetags_modules()
File "c:\python34\lib\functools.py", line 472, in wrapper
result = user_function(*args, **kwds)
File "c:\python34\lib\site-packages\django\template\base.py", line 1360, in get_templatetags_modules
for app_config in apps.get_app_configs())
File "c:\python34\lib\site-packages\django\apps\registry.py", line 137, in get_app_configs
self.check_apps_ready()
File "c:\python34\lib\site-packages\django\apps\registry.py", line 124, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
似乎模板引擎无效。
我现在需要一些帮助,谢谢。
我的urls.py文件如下所示
from django.conf.urls import patterns, include, url
from django.views.generic import TemplateView
# Uncomment the next two lines to enable the admin:
from django.conf import settings
urlpatterns = patterns(
'',
####################index####################
url(r'(?i)^' + settings.BASE_URL + r'$', 'index.views.index'),
url(r'(?i)^' + settings.BASE_URL + r'login$', 'index.login.login'),
url(r'(?i)^' + settings.BASE_URL + r'logout$', 'index.login.logout'),
url(r'(?i)^' + settings.BASE_URL + r'ajaxTest$', 'index.views.ajaxTest'),
url(r'(?i)^' + settings.BASE_URL + r'test$', 'index.test.test'),
)
index的views.py如下所示。
from django.template import loader, RequestContext
from django.http import HttpResponse
from django.shortcuts import render_to_response
import hashlib
import json
from django.conf import settings
def indexProcessors(request):
"A context processor that provides 'app', 'user' and 'ip_address'."
return {
}
def index( request_ ):
viewBag = {
'pageContent': 'Hello world!',
}
content = RequestContext( request_, viewBag, processors= [indexProcessors] )
return render_to_response('base.html', content)