Django Python - 模块未找到

4

我是一名新手,可能做了一些愚蠢的事情。正在运行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")

    )

有人可以帮忙吗?


@NicholasYoung 调试在settings.py中;`DEBUG = TrueTEMPLATE_DEBUG = DEBUGALLOWED_HOSTS = []` - Uma
请提供“找不到模块”错误的完整回溯信息。 - Maxime Lorant
等等,你为什么要将文件路径包含在URL中?首先就不应该这样做。而且我有点累了,但我认为当你只是尝试将变量包含到脚本中时,if语句不会被执行。我可能错了。 - Bioto
@NicholasYoung 抱歉让你等了,如果你有时间的话,明天可以看一下吗?我正在跟随一个在线教程,在Python 2.7上进行操作,但我想在Python 3.3上进行操作(我想我喜欢把事情搞复杂)。当我通过cmd在机器上运行代码时,我得到了P/1.1 404 1712错误。(https://www.youtube.com/watchv=8t80DMAAps8&list=PLEsfXFp6DpzRgedo9IzmcpXYoSeDg29Tx&index=7)Python3中是否与Python2.7有所不同? - Uma
@MaximeLorant你能提供一下帮助吗?这个问题似乎是上面那个错误的扩展。没有人能够解决它。http://stackoverflow.com/questions/23963325/python-django-page-not-found-error-404-static-error - Uma
显示剩余3条评论
1个回答

12

你在导入语句中漏掉了一个 static,请参考文档

from django.conf.urls.static import static
                    # ^^^^^^ this one

目前,它试图将static模块用作函数,但显然这不起作用。当您尝试将模块对象(例如ossys或任何第三方)用作可调用对象(具有__call__方法)时,会引发错误'module' object is not callable


哦,我完全忽略了那个 xD。 - Bioto
我一点头绪也没有,不是我干的。Stackoverflow 让我有点害怕,因为人们总是追求完美。 - Bioto
@MaximeLorant 嘿,Maxine,它起作用了,谢谢...不确定是谁给你投了反对票,抱歉:(。由于我还没有达到最低要求的15个声望,所以我无法给你点赞...但是我一定会在获得声望后立即给你点赞。非常感谢。我现在面临的另一个问题是我的CSS文件没有加载。如果您愿意,我可以创建另一个问题,因为您在此问题上被投票反对...让我知道? - Uma
@MaximeLorant 今天非常感谢你的帮助,保重 :) - Uma
1
@MaximeLorant,这是给你的,我已经有足够的声望来为你点赞了。感谢你的帮助 :) - Uma
显示剩余3条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接