我不断收到没有这样的模块的错误。
项目名称是 gmblnew,我有两个子文件夹-core
而且gmblnew
- 我正在开发的应用程序是核心。
我的urls.py文件是
from django.conf.urls import *
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'gmblnew.views.home', name='home'),
# url(r'^gmblnew/', include('gmblnew.foo.urls')),
url(r'^league/', include('core.views.league')),
# Uncomment the admin/doc line below to enable admin documentation:
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
这似乎很好。views.py文件是:
from django.http import HttpResponse
def league(request):
from core.models import Division
response = HttpResponse()
response['mimetype'] = 'text/plain'
response.write("<HTML><>BODY>\n")
response.write("< TABLE BORDER=1><CAPTION>League List</CAPTION><TR>\n")
all_leagues = Division.objects.all()
for league in all_leagues:
response.write("<TR>\n")
response.write("<TD> %s" % league)
response.write("</TD>\n")
response.write("</BODY></HTML>")
return response
追溯:
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
103. resolver_match = resolver.resolve(request.path_info)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
319. for pattern in self.url_patterns:
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py" in url_patterns
347. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py" in urlconf_module
342. self._urlconf_module = import_module(self.urlconf_name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/Users/chris/Dropbox/Django/gmblnew/gmblnew/urls.py" in <module>
12. url(r'^league/', include('core.views.league')),
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/conf/urls/__init__.py" in include
25. urlconf_module = import_module(urlconf_module)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/importlib.py" in import_module
35. __import__(name)
Exception Type: ImportError at /admin/
Exception Value: No module named league
我已经在该url(r'^league/', include('core.views.league')),
行上尝试了许多变体,包括gmblnew.core.views.league
, views.league
,views.view_league
等。我显然在该行的结构上遗漏了一些超级简单的东西。