尝试上传文件或使用filebrowser为Django创建文件夹时,“CSRF验证失败”

时间:2022-08-03 19:33:55

I have installed filebrowser for Django (not filebrowser3) and when I try to upload a file I recieve the following error:

我为Django安装了filebrowser(不是filebrowser3),当我尝试上传文件时,我收到以下错误:

403 Forbidden

403禁止

CSRF verification failed. Request aborted.

CSRF验证失败。请求中止。

More information is available with DEBUG=True.

有关DEBUG = True的更多信息。

The same error occurs when I try to create a new folder which shows that the problem is that filebrowser cannot create files/direcories within my uploads directory. I am using the default settings and have manually created the /media/uploads directory with it's permissions set as 755.

当我尝试创建一个新文件夹时,会出现同样的错误,该文件夹显示问题是filebrowser无法在我的uploads目录中创建文件/目录。我使用默认设置并手动创建/ media / uploads目录,其权限设置为755。

If I upload a file to the directory then file-browser admin page states:

如果我将文件上传到目录,则文件浏览器管理页面指出:

1 Item Folder: 0 Image: 1

1项目文件夹:0图像:1

I cannot view the image that I have uploaded.

我无法查看我上传的图片。

I have the PIL and sorl.thumbnail modules installed.

我安装了PIL和sorl.thumbnail模块。

5 个解决方案

#1


6  

You are probably using the development version of Django, which includes quite a lot of extra CRSF security. However it's not released yet so external products probably aren't compatible. You should use the 1.1 version of Django instead.

您可能正在使用Django的开发版本,其中包含了大量额外的CRSF安全性。但是它尚未发布,因此外部产品可能不兼容。你应该使用1.1版本的Django。

#2


4  

The Djangodocs have more information about the new Django CSRF requirements:

Djangodocs有关于新的Django CSRF要求的更多信息:

#3


4  

Add to you settings.py this 2 lines:

添加到settings.py这2行:

‘django.middleware.csrf.CsrfViewMiddleware’, ‘django.middleware.csrf.CsrfResponseMiddleware’,

'django.middleware.csrf.CsrfViewMiddleware','django.middleware.csrf.CsrfResponseMiddleware',

#4


1  

See here: http://docs.djangoproject.com/en/dev/ref/contrib/csrf/ like fitzgeralsteele said. Hugs.

见这里:http://docs.djangoproject.com/en/dev/ref/contrib/csrf/就像fitzgeralsteele说的那样。拥抱。

Example: from django.views.decorators.csrf import csrf_exempt

示例:来自django.views.decorators.csrf import csrf_exempt

@csrf_exempt def my_view(request): return HttpResponse(‘Hello world’)

@csrf_exempt def my_view(request):返回HttpResponse('Hello world')

Disable the CSRF middleware.

禁用CSRF中间件。

#5


0  

it work adding

它有用

{% csrf_token %} 

my forms looks like this:

我的表单看起来像这样:

<form method="post" action="">
{% csrf_token %}
{{ form.non_field_errors }}
{{formulario}}
<input type="submit" value="Guardar">
</form>

in to the tags on your template file and verify that 'django.middleware.csrf.CsrfViewMiddleware', is in your settings file, it is in by default

在模板文件上的标签中验证'django.middleware.csrf.CsrfViewMiddleware'是否在您的设置文件中,默认情况下是

#1


6  

You are probably using the development version of Django, which includes quite a lot of extra CRSF security. However it's not released yet so external products probably aren't compatible. You should use the 1.1 version of Django instead.

您可能正在使用Django的开发版本,其中包含了大量额外的CRSF安全性。但是它尚未发布,因此外部产品可能不兼容。你应该使用1.1版本的Django。

#2


4  

The Djangodocs have more information about the new Django CSRF requirements:

Djangodocs有关于新的Django CSRF要求的更多信息:

#3


4  

Add to you settings.py this 2 lines:

添加到settings.py这2行:

‘django.middleware.csrf.CsrfViewMiddleware’, ‘django.middleware.csrf.CsrfResponseMiddleware’,

'django.middleware.csrf.CsrfViewMiddleware','django.middleware.csrf.CsrfResponseMiddleware',

#4


1  

See here: http://docs.djangoproject.com/en/dev/ref/contrib/csrf/ like fitzgeralsteele said. Hugs.

见这里:http://docs.djangoproject.com/en/dev/ref/contrib/csrf/就像fitzgeralsteele说的那样。拥抱。

Example: from django.views.decorators.csrf import csrf_exempt

示例:来自django.views.decorators.csrf import csrf_exempt

@csrf_exempt def my_view(request): return HttpResponse(‘Hello world’)

@csrf_exempt def my_view(request):返回HttpResponse('Hello world')

Disable the CSRF middleware.

禁用CSRF中间件。

#5


0  

it work adding

它有用

{% csrf_token %} 

my forms looks like this:

我的表单看起来像这样:

<form method="post" action="">
{% csrf_token %}
{{ form.non_field_errors }}
{{formulario}}
<input type="submit" value="Guardar">
</form>

in to the tags on your template file and verify that 'django.middleware.csrf.CsrfViewMiddleware', is in your settings file, it is in by default

在模板文件上的标签中验证'django.middleware.csrf.CsrfViewMiddleware'是否在您的设置文件中,默认情况下是