-2

楷模

image_url = models.ImageField(upload_to="uploads/shows",blank=True,null=True)

我需要将图像上传到特定目录。我正在尝试使用管理面板添加这些媒体文件。如何上传图片?

编辑 1

http://192.168.2.9:8000/static/uploads/shows/myImage.jpg

Page not found (404)
Request Method: GET
Request URL:    http://192.168.2.9:8000/static/uploads/shows/myImage.jpg
'uploads/shows/myImage.jpg' could not be found
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.

编辑 2

    # Absolute path to the directory static files should be collected to.
    # Don't put anything in this directory yourself; store your static files
    # in apps' "static/" subdirectories and in STATICFILES_DIRS.
    # Example: "/home/media/media.lawrence.com/static/"
    STATIC_ROOT = ''

    # URL prefix for static files.
    # Example: "http://media.lawrence.com/static/"
    STATIC_URL = '/static/'

# Additional locations of static files
STATICFILES_DIRS = (
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
4

1 回答 1

0

该错误并未说明您的上传失败;据说上传后找不到文件。因此,就像文档中关于“为上传的内容提供服务”的解释一样,您还需要按照他们向我们建议的方式设置媒体设置。

from django.conf import settings
from django.conf.urls.static import static

urlpatterns = patterns('',
    # ... the rest of your URLconf goes here ...
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

然后你也可以上传你的文件

于 2013-09-16T11:51:06.677 回答