为什么我部署的niji修改头像时无法正常显示头像图片

Annabel
Posted 1 year, 1 month ago in General, viewed 1025 times

为什么我部署的niji修改头像时无法正常显示头像图片

8 Replies
  • Annabel
    1 year, 1 month ago

    而且部署好的网站也不能使用这个编辑器,可是python运行的时候却没有问题

  • ugooo
    1 year, 1 month ago

    rey

  • eric
    1 year, 1 month ago

    请问可否提供一下错误日志或者部属的配置文件?

  • eric
    1 year, 1 month ago

    @Annabel ^

  • iHTCboy
    3 months ago

    @eric

    [14/Jun/2019 06:48:53] "GET /avatar/ HTTP/1.1" 200 7033
    1.png [14/Jun/2019 06:49:04] "POST /avatar/ HTTP/1.1" 302 0 [14/Jun/2019 06:49:04] "GET / HTTP/1.1" 200 10142 Not Found: /uploads/forum/avatars/1.png [14/Jun/2019 06:49:04] "GET /uploads/forum/avatars/1.png HTTP/1.1" 404 5948
    

  • iHTCboy
    3 months ago

    @eric

    [14/Jun/2019 06:48:53] "GET /avatar/ HTTP/1.1" 200 7033
    1.png [14/Jun/2019 06:49:04] "POST /avatar/ HTTP/1.1" 302 0 [14/Jun/2019 06:49:04] "GET / HTTP/1.1" 200 10142 Not Found: /uploads/forum/avatars/1.png [14/Jun/2019 06:49:04] "GET /uploads/forum/avatars/1.png HTTP/1.1" 404 5948
    

  • iHTCboy
    3 months ago

    @Annabel

    使用这个编辑器, 在setting里添加 'pagedown',

    INSTALLED_APPS = [
     ...
        'pagedown',
    ...
    ]
    

  • iHTCboy
    3 months ago

    @Annabel

    在urls.py 添加

    urlpatterns = [
    ...
    url(r'^uploads/(?P<path>.*?)/(?P<subpath>.*?)/(?P<filename>.*?)/$', views.get_upload_file, name="get_upload_file"),
    ...
    

    ]

    在view.py添加

    import os
    from django.http import HttpResponse
    
    def get_upload_file(request, path, subpath, filename):
        file_path = os.getcwd() + '/uploads/{}/{}/{}'.format(path, subpath, filename)
        print(file_path)
        if os.path.isfile(file_path):
            try:
                with open(file_path, 'rb') as f:
                    image_data = f.read()
                return HttpResponse(image_data, content_type="image/png")
            except Exception as e:
                print(e)
    
        return HttpResponse(str('404: Not Found'))
    

    这样就可以显示图片啦

Leave a Reply
NIJI APP
NIJI is a forum app built with Django

General

General discussions about Django, Python, Nijiforum etc.