【发布时间】:2014-07-19 19:50:53
【问题描述】:
我是新手,所以我可能做了一些愚蠢的事情。运行 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")
)
有人可以帮忙吗?
【问题讨论】:
-
变量 DEBUG 在哪里?看起来它没有被设置,所以你试图调用的所有东西都没有被正确执行。
-
@TimCastelijns 第 22 行是
document_root=settings.STATIC_ROOT),它是 urls.py 代码块的一部分:if settings.DEBUG: urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) -
@NicholasYoung 调试在settings.py中;
DEBUG = True TEMPLATE_DEBUG = DEBUG ALLOWED_HOSTS = [] -
请提供“Module not found”错误的完整回溯。
-
等等,你为什么要在 url 中包含文件路径?你一开始就不应该。我也有点累,但我不认为当你试图将变量包含到脚本中时 if 会运行。我可能错了
标签: python django django-settings