gpt4 book ai didi

python - 在 django 管理面板中选择图像时,Filebrowser 不会在文件路径中附加斜杠

转载 作者:太空宇宙 更新时间:2023-11-03 19:12:17 25 4
gpt4 key购买 nike

使用 python 2.7、django 1.4.1、filebrowser 3.5.0、grappelli 2.4.2、win7 x64

这就是我的问题:

我正在创建一个对象,并尝试将图像附加到它:

点击搜索: filebrowser attaching file

浏览文件夹找到我的文件,然后选择它: enter image description here

我选择它后,这是它返回的路径:

enter image description here

附加模型本身:

class EntryManager(models.Manager):
def active(self):
return super(EntryManager, self).get_query_set().filter(is_active=True)

class Services(models.Model):
name = models.CharField(max_length = 20, help_text = 'Nazwa oferowanej usługi', verbose_name='Usługa')
slug = models.SlugField(max_length=255, help_text = 'Odnośnik, generowany automatycznie na podstawie nazwy', unique=True,verbose_name='Odnośnik')
icon = FileBrowseField(verbose_name='Ikona', max_length=255, directory="images/", extensions=[".jpg",'.png','.gif'], blank=True, null=True,help_text = '.jpg, .png, .gif')
is_active = models.BooleanField(help_text='Zaznacz aby obiekt był widoczny dla użytkowników', default=False)

objects = EntryManager()

class Meta:
ordering = ['name']
verbose_name = "Usługę"
verbose_name_plural = "Usługi"
def __str__(self):
return self.name
def __unicode__(self):
return self.name
def get_absolute_url(self):
return '/uslugi/%s/' % self.slug

我现在不知道在哪里寻找问题,any1 可以帮忙吗?

编辑:

url.py

from django.conf.urls import patterns, include, url

from django.contrib import admin
admin.autodiscover()

from filebrowser.sites import site


#when on dev, serve media files
from django.conf import settings

urlpatterns = patterns('',

url(r'^grappelli/', include('grappelli.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^admin/filebrowser/', include(site.urls)),
url(r'^uslugi/?$', 'services.views.services'),
)

#when on dev, serve media files
if settings.DEBUG:
# static files (images, css, javascript, etc.)
urlpatterns += patterns('',
(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
'document_root': settings.MEDIA_ROOT}))

以及settings.py的一部分

import os
PROJECT_DIR = os.path.abspath(os.path.dirname(__file__) + "../../")
MEDIA_ROOT = os.path.join(PROJECT_DIR, 'site_media/media')
STATIC_ROOT = os.path.join(PROJECT_DIR, 'site_media/static')
ADMIN_MEDIA_PREFIX = os.path.join(PROJECT_DIR, 'site_media/admin_media')

INSTALLED_APPS = (
'grappelli',
'filebrowser',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'services'
)

最佳答案

读完你的urls.py后,我需要向你展示Documentation :

In your url.py import the default FileBrowser site:

from filebrowser.sites import site

and add the following URL-patterns (before any admin-urls):

urlpatterns = patterns('',
url(r'^admin/filebrowser/', include(site.urls)),
)

所以你和我的新项目之间的唯一区别是:

  1. 我在 VirtualBox 和 Windows 7 上使用 Linux Ubuntu x86
  2. 在任何管理网址之前我有 /admin/file-browser:

from django.conf.urls import patterns, include, url
from django.contrib import admin
from filebrowser.sites import site
from django.conf.urls.static import static
from django.conf import settings

admin.autodiscover()

urlpatterns = static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + patterns('',
url(r'^grappelli/', include('grappelli.urls')),
url(r'^admin/filebrowser/', include(site.urls)),
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^i18n/', include('django.conf.urls.i18n')),
url(r'^', include('django.contrib.flatpages.urls')),
)

关于python - 在 django 管理面板中选择图像时,Filebrowser 不会在文件路径中附加斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12548659/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com