1

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

所以这是我的问题:

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

点击搜索: 文件浏览器附加文件

浏览文件夹以获取我的文件,然后选择它: 在此处输入图像描述

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

在此处输入图像描述

附加模型本身:

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

我现在不知道在哪里搜索问题,有什么帮助吗?

编辑:

网址.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'
)
4

1 回答 1

1

阅读您的之后urls.py,我需要向您展示文档

在您的 url.py 中导入默认的 FileBrowser 站点:

from filebrowser.sites import site

并添加以下 URL 模式(在任何 admin-url 之前):

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

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

  1. 我在 VirtualBox undex 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')),
)
于 2012-09-23T11:05:24.063 回答