我遇到了這個問題很長一段時間,並且在解決這個問題時遇到了問題。現在我使用Django 1.2.4,並具有以下設置:django:無法找到靜態文件
AUTH_PROFILE_MODULE = 'customUsers.UserProfile'
TEMPLATE_STRING_IF_INVALID = 'Error generating variable'
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ANONYMOUS_USER_ID = -1
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend', # default
'guardian.backends.ObjectPermissionBackend',
)
MANAGERS = ADMINS
TEMPLATE_CONTEXT_PROCESSORS = ("django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
# "django.core.context_processors.static", there is no this function in the file
"django.contrib.messages.context_processors.messages",
"customUsers.user_cp_context.userCPContext")
USE_I18N = False
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = '/Users/carrier24sg/Documents/workspace/static_teachers/'
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = '/media/'
# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = '/media/admin/'
# Make this unique, and don't share it with anybody.
SECRET_KEY = '([email protected]#535*vivl#lcv06=v*hvae#&6mx15nzt'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
#ROOT_URLCONF = 'myproject.urls'
#TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
# '/home/carrier24sg/webapps/django/myproject/templates'
#)
SITE_ID = 2
ROOT_URLCONF = 'teachers.urls'
TEMPLATE_DIRS = (
'/Users/carrier24sg/Documents/workspace/templates',
'/Users/carrier24sg/Documents/workspace/teachers/templates'
)
INSTALLED_APPS = (
'customUsers',
'ConsentForm',
'teachers.consent_teachers',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'conversation',
'teachers.student_profiling',
'south',
'guardian',
'persistent_messages',)
對於一些原因,我不能像服務JS和CSS靜態文件。開發服務器的輸出顯示404錯誤"GET /media/common/css/sidebar.css HTTP/1.1" 404 2202
我已經嘗試在瀏覽器上輸入靜態文件的URL,而不是告訴我該文件找不到(我期待的),我顯示了url-unmatched django調試頁面Using the URLconf defined in teachers.urls, Django tried these URL patterns, in this order: ......The current URL, media/js/conversation_load.js, didn't match any of these.
問題:爲什麼django沒有讀取像http://127.0.0.1:8000/media/js/conversation_load.js
這樣的靜態文件請求?
隨機猜測:你還沒有在你的urls.py中設置任何內容來匹配'media'。 –
@Daniel,我在遠程主機上有一個副本,在urls.py中沒有這樣的設置,但工作原理完全相同!? – goh
是的,因爲你可能已經設置了Apache來指向媒體目錄。請仔細閱讀[文檔](https://docs.djangoproject.com/en/1.2/howto/static-files/)。 –