我正在创建一个测试环境的简单项目,项目结构如下所示
root/
manage.py
mysite/
apps/
__init__.py
app1/
urls.py
views.py
settings.py
urls.py
__init__.py
在settings.py文件中,我在INSTALLED_APPS中安装app1,当我尝试修改root urls.py时
url(r'^app1/', include('apps.app1.urls')),
我收到以下错误
Traceback (most recent call last):
File "D:\Python33\lib\site-packages\django\core\urlresolvers.py", line 339, in urlconf_module
return self._urlconf_module
AttributeError: 'RegexURLResolver' object has no attribute '_urlconf_module'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Python33\lib\site-packages\django\core\handlers\base.py", line 101, in get_response
resolver_match = resolver.resolve(request.path_info)
File "D:\Python33\lib\site-packages\django\core\urlresolvers.py", line 318, in resolve
for pattern in self.url_patterns:
File "D:\Python33\lib\site-packages\django\core\urlresolvers.py", line 346, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "D:\Python33\lib\site-packages\django\core\urlresolvers.py", line 341, in urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "D:\Python33\lib\importlib\__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 584, in _check_name_wrapper
File "<frozen importlib._bootstrap>", line 1022, in load_module
File "<frozen importlib._bootstrap>", line 1003, in load_module
File "<frozen importlib._bootstrap>", line 560, in module_for_loader_wrapper
File "<frozen importlib._bootstrap>", line 868, in _load_module
File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
File "D:/project/worldcup\worldcup\urls.py", line 4, in <module>
url(r'^app1/', include('apps.app1.urls')),
File "D:\Python33\lib\site-packages\django\conf\urls\__init__.py", line 26, in include
urlconf_module = import_module(urlconf_module)
File "D:\Python33\lib\importlib\__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
File "<frozen importlib._bootstrap>", line 1512, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
File "<frozen importlib._bootstrap>", line 1512, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
File "<frozen importlib._bootstrap>", line 1529, in _find_and_load_unlocked
ImportError: No module named 'apps'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Python33\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "D:\Python33\lib\site-packages\django\contrib\staticfiles\handlers.py", line 67, in __call__
return self.application(environ, start_response)
File "D:\Python33\lib\site-packages\django\core\handlers\wsgi.py", line 206, in __call__
response = self.get_response(request)
File "D:\Python33\lib\site-packages\django\core\handlers\base.py", line 196, in get_response
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
File "D:\Python33\lib\site-packages\django\core\handlers\base.py", line 231, in handle_uncaught_exception
return debug.technical_500_response(request, *exc_info)
File "D:\Python33\lib\site-packages\django\views\debug.py", line 69, in technical_500_response
html = reporter.get_traceback_html()
File "D:\Python33\lib\site-packages\django\views\debug.py", line 323, in get_traceback_html
c = Context(self.get_traceback_data())
File "D:\Python33\lib\site-packages\django\views\debug.py", line 281, in get_traceback_data
frames = self.get_traceback_frames()
File "D:\Python33\lib\site-packages\django\views\debug.py", line 428, in get_traceback_frames
pre_context_lineno, pre_context, context_line, post_context = self._get_lines_from_file(filename, lineno, 7, loader, module_name)
File "D:\Python33\lib\site-packages\django\views\debug.py", line 379, in _get_lines_from_file
source = loader.get_source(module_name)
File "<frozen importlib._bootstrap>", line 605, in _requires_frozen_wrapper
ImportError: importlib._bootstrap is not a frozen module
[08/Dec/2013 22:25:59] "GET /user/hello/ HTTP/1.1" 500 59
我的开发环境是python 3.3,django 1.6,win 7
任何人都可以帮助我解决这个问题,谢谢以前!
答案 0 :(得分:0)
快速修复修改
url(r'^app1/', include('apps.app1.urls')),
到
url(r'^app1/', include('s20462310mysite.apps.app1.urls')),
更好的方法是将文件夹结构更改为:
root/
manage.py
app1/
__init__.py
urls.py
views.py
mysite/
__init__.py
settings.py
urls.py
__init__.py
然后使用
url(r'^app1_new/', include('app1.urls')),
其他说明:
您实际上并不需要应用程序文件夹中的models.py
在Django 1.6中你不需要“ _ init _ .py”
但拥有这些文件是一个好习惯