Django:1.3.5
nginx:1.2.6
uwsgi:1.0.5
我的 django 应用程序在 nginx 和 uwsgi 上运行。打开管理页面时,出现 500 错误。此错误是“ImportError:没有名为 urls 的模块”。
运行命令“python manage.py runserver”并打开管理页面,然后没有出现500错误。
在 urls.py 上评论管理员,然后不会发生错误。
此错误仅发生在 nginx 和 uwsgi 上。
我该如何解决?
网址.py
from django.conf.urls.defaults import *
from django.conf import settings
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^blog/', include('myApp.blog.urls')),
(r'^admin/', include(admin.site.urls))
)
wsgi.py
import os
import sys
import site
reload(sys)
sys.setdefaultencoding('utf-8')
sys.path.append('/path/to/myApp/')
site.addsitedir('/usr/lib/python2.6/site-packages')
os.environ['DJANGO_SETTINGS_MODULE'] = 'myApp.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
错误回溯
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.6/site-packages/django/contrib/admin/sites.py", line 214, in wrapper
return self.admin_view(view, cacheable)(*args, **kwargs)
File "/usr/lib/python2.6/site-packages/django/utils/decorators.py", line 93, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.6/site-packages/django/views/decorators/cache.py", line 79, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.6/site-packages/django/contrib/admin/sites.py", line 197, in inner
return view(request, *args, **kwargs)
File "/usr/lib/python2.6/site-packages/django/views/decorators/cache.py", line 79, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.6/site-packages/django/contrib/admin/sites.py", line 382, in index
context_instance=context_instance
File "/usr/lib/python2.6/site-packages/django/shortcuts/__init__.py", line 20, in render_to_response
return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/usr/lib/python2.6/site-packages/django/template/loader.py", line 188, in render_to_string
return t.render(context_instance)
File "/usr/lib/python2.6/site-packages/django/template/base.py", line 123, in render
return self._render(context)
File "/usr/lib/python2.6/site-packages/django/template/base.py", line 117, in _render
return self.nodelist.render(context)
File "/usr/lib/python2.6/site-packages/django/template/base.py", line 744, in render
bits.append(self.render_node(node, context))
File "/usr/lib/python2.6/site-packages/django/template/base.py", line 757, in render_node
return node.render(context)
File "/usr/lib/python2.6/site-packages/django/template/loader_tags.py", line 127, in render
return compiled_parent._render(context)
File "/usr/lib/python2.6/site-packages/django/template/base.py", line 117, in _render
return self.nodelist.render(context)
File "/usr/lib/python2.6/site-packages/django/template/base.py", line 744, in render
bits.append(self.render_node(node, context))
File "/usr/lib/python2.6/site-packages/django/template/base.py", line 757, in render_node
return node.render(context)
File "/usr/lib/python2.6/site-packages/django/template/loader_tags.py", line 127, in render
return compiled_parent._render(context)
File "/usr/lib/python2.6/site-packages/django/template/base.py", line 117, in _render
return self.nodelist.render(context)
File "/usr/lib/python2.6/site-packages/django/template/base.py", line 744, in render
bits.append(self.render_node(node, context))
File "/usr/lib/python2.6/site-packages/django/template/base.py", line 757, in render_node
return node.render(context)
File "/usr/lib/python2.6/site-packages/django/template/defaulttags.py", line 311, in render
return self.nodelist_true.render(context)
File "/usr/lib/python2.6/site-packages/django/template/base.py", line 744, in render
bits.append(self.render_node(node, context))
File "/usr/lib/python2.6/site-packages/django/template/base.py", line 757, in render_node
return node.render(context)
File "/usr/lib/python2.6/site-packages/django/template/defaulttags.py", line 311, in render
return self.nodelist_true.render(context)
File "/usr/lib/python2.6/site-packages/django/template/base.py", line 744, in render
bits.append(self.render_node(node, context))
File "/usr/lib/python2.6/site-packages/django/template/base.py", line 757, in render_node
return node.render(context)
File "/usr/lib/python2.6/site-packages/django/template/loader_tags.py", line 64, in render
result = block.nodelist.render(context)
File "/usr/lib/python2.6/site-packages/django/template/base.py", line 744, in render
bits.append(self.render_node(node, context))
File "/usr/lib/python2.6/site-packages/django/template/base.py", line 757, in render_node
return node.render(context)
File "/usr/lib/python2.6/site-packages/django/template/defaulttags.py", line 437, in render
url = reverse(view_name, args=args, kwargs=kwargs, current_app=context.current_app)
File "/usr/lib/python2.6/site-packages/django/core/urlresolvers.py", line 391, in reverse
*args, **kwargs)))
File "/usr/lib/python2.6/site-packages/django/core/urlresolvers.py", line 312, in reverse
possibilities = self.reverse_dict.getlist(lookup_view)
File "/usr/lib/python2.6/site-packages/django/core/urlresolvers.py", line 229, in _get_reverse_dict
self._populate()
File "/usr/lib/python2.6/site-packages/django/core/urlresolvers.py", line 208, in _populate
For name in pattern.reverse_dict:
File "/usr/lib/python2.6/site-packages/django/core/urlresolvers.py", line 229, in _get_reverse_dict
self._populate()
File "/usr/lib/python2.6/site-packages/django/core/urlresolvers.py", line 208, in _populate
For name in pattern.reverse_dict:
File "/usr/lib/python2.6/site-packages/django/core/urlresolvers.py", line 229, in _get_reverse_dict
self._populate()
File "/usr/lib/python2.6/site-packages/django/core/urlresolvers.py", line 197, in _populate
For pattern in reversed(self.url_patterns):
File "/usr/lib/python2.6/site-packages/django/core/urlresolvers.py", line 279, in _get_url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/lib/python2.6/site-packages/django/core/urlresolvers.py", line 274, in _get_urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "/usr/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
ImportError: No module named urls
设置.py (INSTALLED_APPS)
ROOT_URLCONF = 'myApp.urls'
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'django.contrib.sitemaps',
'django.contrib.markup',
'myApp.blog',
)