在做一个 Blog,本地使用 python manage.py runserver 没有问题。commit 到 sae 之后出现 “No module name urls” 错误。
版本
python 2.7
django 1.6.4
平台
SAE
之前能很好地运行。
我创建第二个应用之后,把 urlpattern 都写在主 urls 上,也是妥妥的。
当我把urlpattern 按应用地址分开,然后分别写在相应应用下的 urls 中,再从主 urls 中 include 它们。这时在本地运行没有问题,上传到 SAE 后就出现了 “No module name urls” 错误。
可能是哪里出错了呢?
谢先!
错误信息如下:
Traceback (most recent call last):
File "/usr/local/sae/python/lib/python2.7/site-packages/sae/__init__.py", line 18, in new_app
return app(environ, start_response)
File "/data1/www/htdocs/664/dawnstr/1/site-packages/django/core/handlers/wsgi.py", line 206, in __call__
response = self.get_response(request)
File "/data1/www/htdocs/664/dawnstr/1/site-packages/django/core/handlers/base.py", line 196, in get_response
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
File "/data1/www/htdocs/664/dawnstr/1/site-packages/django/core/handlers/base.py", line 234, in handle_uncaught_exception
if resolver.urlconf_module is None:
File "/data1/www/htdocs/664/dawnstr/1/site-packages/django/core/urlresolvers.py", line 360, in urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "/data1/www/htdocs/664/dawnstr/1/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/data1/www/htdocs/664/dawnstr/1/newblog/urls.py", line 14, in <module>
url(r'^blog/', include('blog.urls')),
File "/data1/www/htdocs/664/dawnstr/1/site-packages/django/conf/urls/__init__.py", line 26, in include
urlconf_module = import_module(urlconf_module)
File "/data1/www/htdocs/664/dawnstr/1/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
ImportError: No module named urls
这是三个 urls.py 文件
主文件(mysite)
from django.conf.urls import patterns, include, url
from django.views.generic.base import TemplateView
from blog.models import Article
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^books/', include('books.urls')),
url(r'^blog/', include('blog.urls')),
url(r'^$', TemplateView.as_view(template_name='index.html'), name='index'),
)
应用1(blog)
from django.conf.urls import patterns, url
from django.views.generic.base import TemplateView
urlpatterns = patterns('blog.views',
url(r'^$', 'home_page'),
url(r'^home/$', 'home_page', name='home'),
url(r'^archive/$', 'article_list', name='archive'),
url(r'^about/$', TemplateView.as_view(template_name='about.html'), name='about'),
url(r'^search/$', 'search', name='search'),
url(r'^article/(?P<pid>\d+)/(?P<year>\d+)/(?P<month>\d+)/(?P<day>\d+)/$', 'article_page', name='article_page'),
url(r'^tag/(?P<slug>[\w-]+)/$', 'article_list_of_tag'),
url(r'^category/(?P<slug>[\w-]+)/$', 'article_list_of_category'),
)
应用2(books)
from django.conf.urls import patterns, url
urlpatterns = patterns('books.views',
url(r'^$', 'book_list'),
url(r'(?P<id>\d+)/$', 'book_detail'),
url(r'star/$', 'book_starred'),
)
暂时的解决办法
把 urlpattern 写在主urls上,不要分开写。