Django django-adminfiles [英] Django django-adminfiles

查看:188
本文介绍了Django django-adminfiles的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Django创建一个Blog,我需要在帖子上插入图片。据我所知,最好的方案是 django-adminfiles

I'm creating a Blog with Django and I need to insert images on the posts. As far as I know, the best package for that is django-adminfiles

安装指南非常简单,但我不明白第3步(因为我的英语水平不好:S):

The installation guide is pretty simple but I don't understand the 3rd step(because of my bad English level :S):

在STATIC_URL / adminfiles中提供adminfiles / static / adminfiles目录的内容。这可以通过您的网络服务器配置,通过django.contrib.staticfiles等应用程序,或通过复制文件或制作符号链接来完成。

Make the contents of the adminfiles/static/adminfiles directory available at STATIC_URL/adminfiles. This can be done by through your webserver configuration, via an app such as django.contrib.staticfiles, or by copying the files or making a symlink.

我已经运行了collecstatic,将adminfiles / static / adminfiles的文件复制到我的静态目录,似乎没有任何工作。当我写一篇文章时,它应该出现在这个视频中,但是图像的缩略图和All uploads images,上传,刷新....不会出现。
我对Django很新,我对这个愚蠢的问题有点失落。 ¿有人知道我在这里要做什么吗?

I have run collecstatic, copy the files of adminfiles/static/adminfiles to my static directory and nothing seems to work. When I write a post, it should appear like in this video but the image thumbmails and "All uploads images","Upload","Refresh".... doesn't appear. I'm pretty new to Django and I'm a bit lost with this silly question. ¿Does someone know what i have to do here?

推荐答案

我的环境




  • 操作系统:CentOS7_x86_64

  • Python:2.7.5(必须是devel版本)

  • Django:1.8。 1

  • My environment

    • OS: CentOS7_x86_64
    • Python: 2.7.5 (must be devel version)
    • Django: 1.8.1

      1. 安装

      1. Install


      • 'adminfiles'
        pip install django -adminfiles == 1.0.1

      'sorl-thumbnail'
      pip install sorl-thumbnail == 12.2

      先决条件'枕头'
      yum install libtiff-devel libjpeg-devel libzip-devel freetype-devel lcms2-devel libwebp-devel tcl-devel tk-devel -y

      '枕头'
      pip安装枕头== 2.8.1

      使用adminfiles

      Use adminfiles

      我创建了一个名为'demo'的django项目,它只有一个应用程序'试用'。

      I have created a django project named 'demo', it has only one app 'trial'.

      
           demo
             |
             |------ demo
             |        |---- __init__.py
             |        |---- settings.py
             |        |---- urls.py
             |        |---- wsgi.py
             |
             |------ manage.py
             |------ trial
                       |---- \aa___init__.py
                       |---- admin.py
                       |---- models.py
                       |---- tests.py
                       |---- views.py
          


      要在'demo'项目中使用adminfiles,我们必须执行以下操作:

      To use adminfiles in the 'demo' project we must do the following:


      • 添加'adminfiles','sorl .thumbnail'到demo / settings.py文件的INSTALLED_APPS元组。

      • Add 'adminfiles', 'sorl.thumbnail' to INSTALLED_APPS tuple of demo/settings.py file.

      
      INSTALLED_APPS = (
          'django.contrib.admin',
          'django.contrib.auth',
          'django.contrib.contenttypes',
          'django.contrib.sessions',
          'django.contrib.messages',
          'django.contrib.staticfiles',
          'adminfiles',
          'sorl.thumbnail',
          'trial',
      )
      


    • 将adminfiles网址添加到urlatterns demo / urls.py文件列表。

    • Add adminfiles url to the urlatterns list of demo/urls.py file.

      
      urlpatterns = [
          url(r'^admin/', include(admin.site.urls)),
          url(r'^adminfiles/', include('adminfiles.urls')),
      ]
      


    • 修改试用/管理员的管理员。 py文件。

      (注意:文章是在trial / models.py中定义的模型,它有一个名为'text'的TextField字段)

    • Modify admin of trial/admin.py file.
      (Note: Article is a model defined in trial/models.py, it has a TextField field named 'text')

      
      from django.contrib import admin
      from models import Article
      
      from adminfiles.admin import FilePickerAdmin
      
      admin.site.register(Article)
      
      class ExtraAdmin(FilePickerAdmin):
         adminfiles_fields = ('text',)
      
      admin.site.register(Article, ExtraAdmin)
      


    • python manage.py migrate

    • python manage.py migrate

      设置MEDIA_URL和MEDIA_ROOT。

      Set MEDIA_URL and MEDIA_ROOT.

      demo / settings.py:

      demo/settings.py :

      
      MEDIA_URL = '/media/'
      MEDIA_ROOT = '/data/media/'
      

      demo / urls.py:

      demo/urls.py :

      
      from django.conf import settings
      from django.conf.urls.static import static
      
      urlpatterns = [
        url(r'^admin/', include(admin.site.urls)),
        url(r'^adminfiles/', include('adminfiles.urls')),
      ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
      

      完成上述设置后,上传文件将会存储在'/ data / media / adminfiles /'目录中。

      After the above settings, the upload files will be stored in '/data/media/adminfiles/' dir.

      这篇关于Django django-adminfiles的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆