Django Admin:上传文件的路径错误.缺少"静态"?

acs*_*tos 7 django django-admin

我有一个简单的模型和django中的默认管理员.一切都按预期工作,我可以上传文件.我已经阅读了关于上传路径的django文档.我的MEDIA URL和MEDIA ROOT已设置并且上传有效.让我说我登录默认管理员,下载一个上传的jpg订单,我去编辑订单,我看到当前的上传文件.

如果我悬停当前文件链接,完整的URL是some.url.com/uploads/myfile.jpg,当它应该是some.url.com/static/uploads/myfile.jpg ???

我的MEDIA URL在some.url.com/static/和MEDIA ROOT设置为"静态"的绝对路径.

由于上传工作正常并且应该到达应有的位置,可能会缺少某些内容......

我希望能够,在默认的django管理员中,转到订单编辑,将当前上传的文件悬停,点击它,它将在新窗口中打开,显然,目前它是404 ...

模型的相关部分:

ficheiro = models.FileField(upload_to='uploads')
Run Code Online (Sandbox Code Playgroud)

下面是截图: 截图http://anibalcascais.com/exemplo.jpg

谢谢

# Django settings for ensanis project.
import os.path


DEBUG = False
TEMPLATE_DEBUG = DEBUG

ADMINS = (
    # ('Anibal Santos', 'anibalcascais@gmail.com'),
)

MANAGERS = ADMINS

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'Europe/Lisbon'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'pt_PT'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = '/home/anibal/sites/ensanis/static/'

# 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 = 'http://cl10.anibalcascais.com/static/'

# 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 = 'http://cl10.anibalcascais.com/media/'



# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.load_template_source',
    'django.template.loaders.app_directories.load_template_source',
#     'django.template.loaders.eggs.load_template_source',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
)

ROOT_URLCONF = 'ensanis.urls'

TEMPLATE_DIRS = ( 
    'templates',
)



INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'ensanis.encomendas',
    'django.contrib.admin',
    'ensanis.django_evolution',
)
Run Code Online (Sandbox Code Playgroud)

小智 2

好吧,很抱歉打扰大家,但事实证明这是显而易见的事情:我已经重新启动了 fcgi 并且路径现在是正确的。(呃!)

很抱歉给您带来麻烦:)

  • OT:我只是想提一下,这个问题是经过深思熟虑且详细的;虽然很明显 OP 不是 Django 专家,但你还是竭尽全力尝试尽可能最好地描述问题。带箭头的屏幕截图虽然不是绝对必要的,但确实让我想尽力帮助您。:-) 欢迎来到SO! (2认同)