Django 管理员:上传文件的路径错误。缺少“静态”?

发布于 2024-08-23 05:46:36 字数 3027 浏览 6 评论 0原文

我有一个简单的模型和 django 中的默认管理员。一切都按预期进行,我可以上传文件。 我已经阅读了有关上传路径的 django 文档。 我的媒体 URL 和媒体根已设置并且上传工作正常。 假设我登录到默认管理员,使用上传的 jpg 下订单,然后我去编辑订单,然后看到当前上传的文件。

如果我将鼠标悬停在当前文件链接上,则完整的 url 是 some.url.com/uploads/myfile.jpg,而它应该是 some.url.com/static/uploads/myfile.jpg ???

我的媒体 URL 设置为 some.url.com/static/,媒体根设置为“static”的绝对路径。

由于上传工作正常并且到达了它应该去的地方,也许缺少一些东西...

我希望能够在默认的 django admin 内,转到订单编辑,将鼠标悬停在当前上传的文件上,单击它,它将在一个新窗口,显然,当前它变为 404...

模型中的相关部分:

ficheiro = models.FileField(upload_to='uploads')

这是屏幕截图: 截图http://anibalcascais.com/exemplo.jpg

谢谢

# Django settings for ensanis project.
import os.path


DEBUG = False
TEMPLATE_DEBUG = DEBUG

ADMINS = (
    # ('Anibal Santos', '[email protected]'),
)

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',
)

I have a simple model and the default admin in django. Everything works as expected and I can upload files.
I've read the django docs regarding upload paths.
My MEDIA URL and MEDIA ROOT are set and the uploading works.
Lets say I login into the default admin, place an order with an uploaded jpg, the I go to edit the order and I see the current upload file.

If I hover the current file link, the complete url is some.url.com/uploads/myfile.jpg, when it should be some.url.com/static/uploads/myfile.jpg ???

My MEDIA URL is set at some.url.com/static/ and MEDIA ROOT at the absolute path to "static".

Since the upload works fine and goes where it should, maybe something is missing...

I'd like to be able to, inside default django admin, go to order edit, hover the current uploaded file, click it and it would open in a new window, Obviously, currently it goes 404...

The relevant part from the model:

ficheiro = models.FileField(upload_to='uploads')

Heres a screenshot:
screenshot http://anibalcascais.com/exemplo.jpg

Thank You

# Django settings for ensanis project.
import os.path


DEBUG = False
TEMPLATE_DEBUG = DEBUG

ADMINS = (
    # ('Anibal Santos', '[email protected]'),
)

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',
)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终止放荡 2024-08-30 05:46:36

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

很抱歉给您带来麻烦:)

ok, I'm sorry to bother you all, but it turns out it was something obvious:
I've restarted fcgi and the paths are now correct. (duhhh!)

Sorry all for your trouble :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文