Django Python - 模块未找到
我还是个新手,可能做了一些傻事。我在用Python 3.3和Django 1.6.2。
当我通过命令行启动本地服务器时,出现了这个错误:“P/1.1 404 1712”,而浏览器里显示的错误是“找不到模块”,异常信息指向urls.py的第22行;
document_root=settings.STATIC_ROOT)
这是urls.py的一部分:
from django.conf.urls import patterns, include, url
from django.conf import settings
from django.conf.urls import static
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
url(r'^$', 'signups.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
)
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL,
document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT)
这是我的settings.py的样子:
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/
STATIC_URL = '/whattheheck/static/'
# Template location
TEMPLATE_DIRS = {
os.path.join(os.path.dirname(BASE_DIR), "whattheheck", "static", "templates"),
}
if DEBUG:
MEDIA_URL = '/whattheheck/media/'
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "whattheheck", "static", "static-only")
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), "whattheheck", "static", "media")
STATICFLIES_DIRS = (
os.path.join(os.path.dirname(BASE_DIR), "whattheheck", "static", "static")
)
有人能帮帮我吗?
1 个回答
12
你在导入语句中忘记加一个 static
了,可以看看文档:
from django.conf.urls.static import static
# ^^^^^^ this one
现在,它试图把 static
模块当成一个函数来用,但显然这样是不行的。当你试图把一个模块对象(比如 os
、sys
或其他第三方模块)当作可调用的东西来使用时,就会出现错误 'module' object is not callable
。