无法在Python中上载图像
型号无法在Python中上载图像,python,django,django-admin,Python,Django,Django Admin,型号 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://
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',
)
错误并不是说你的上传失败;它说一旦上传文件就找不到了。因此,正如文档中解释的那样,您还需要按照他们向我们建议的方式设置媒体设置
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)
然后你的文件也会出现当你尝试时会发生什么?你需要设置@FoxMaSk,请检查编辑。