django suspicious operation on image upload(django对图片上传的可疑操作)
本文介绍了django对图片上传的可疑操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的管理员中,我尝试上传图片,点击保存后出现此错误:
In my admin I try to upload an image and after clicking save I get this error:
SuspiciousOperation at /admin/the_chooser/book/add/
Attempted access to '/media/51VqHa8exoL.jpg' denied.
Request Method: POST
Request URL: http://localhost/admin/the_chooser/book/add/
Django Version: 1.5.2
Exception Type: SuspiciousOperation
Exception Value:
Attempted access to '/media/51VqHa8exoL.jpg' denied.
Exception Location: /Users/username/.virtualenvs/django_books/lib/python2.7/site-packages/django/core/files/storage.py in path, line 259
Python Executable: /usr/bin/python
Python Version: 2.7.2
Python Path:
['/Library/Python/2.7/site-packages/pip-1.3.1-py2.7.egg',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC',
'/Library/Python/2.7/site-packages',
'/Library/Python/2.7/site-packages/setuptools-0.6c11-py2.7.egg-info',
'/Users/username/Projects/django_books/',
'/Users/username/.virtualenvs/django_books/lib/python2.7/site-packages']
我刚刚将 Python Imaging Library 安装到我的 virtualenv 中.这是我的 models.py 文件:
I just installed the Python Imaging Library to my virtualenv. This is my models.py file:
from django.db import models
LITERARY_TYPE = (
('F', 'Fiction'),
('N', 'Non-ficiton'),
)
class Book(models.Model):
name = models.CharField(max_length=200)
author = models.CharField(max_length=200,blank=True,null=True)
slug = models.SlugField(unique=True)
literary_type = models.CharField(max_length=1, choices=LITERARY_TYPE)
description = models.TextField(blank=True)
added = models.DateField(blank=True,null=True,auto_now_add=True)
cover = models.ImageField(blank=True,null=True,upload_to='/media/')
def __unicode__(self):
return self.name
这是我第一次在 Django 中使用文件字段.我的 upload_to
参数是否正确?还有别的问题吗?
This is my first time working with file fields in Django. Is my upload_to
parameter correct? Is something else the issue?
推荐答案
删除你的upload_to路径中的第一个斜杠,使其显示为:upload_to='媒体/'
Remove the first slash in your upload_to path so that it reads: upload_to='media/'
这篇关于django对图片上传的可疑操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:django对图片上传的可疑操作


基础教程推荐
猜你喜欢
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 求两个直方图的卷积 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 包装空间模型 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01