Django POST request to my view from Pyres worker

I'm using Pyres workers to do some processing of data users enter in a form. Their processing is done by a view on my form, which I make a POST request to, with data including the data to process and a CSRF middleware token for the user. My issue is that this is apparently not enough, as Django still rejects my request with a 403 forbidden. Relevant code: Form handler: def handler(req

Django POST请求从我的观点从Pyres工作

我正在使用Pyres工作人员对表单中的数据用户进行一些处理。 他们的处理是通过我的表单上的视图完成的,我通过该表单进行POST请求,其中包含要处理的数据以及用户的CSRF中间件令牌。 我的问题是,这显然是不够的,因为Django仍然拒绝了我的要求,禁止403。 相关代码: 表单处理器: def handler(request): if(request.method == "POST"): if(request.POST.__contains__("taskdata")): #valid post

Can't assign a value (user id) to a ForeignKey field

I am getting the following error: Cannot assign "<django.db.models.fields.related.ForeignKey>": "Worry.user" must be a "User" instance. I trying to assign the id of the current user to an object I have just created. This is part of my models.py: from django.contrib.auth.models import User from django.forms import ModelForm from django.db import models

无法将值(用户标识)分配给ForeignKey字段

我收到以下错误: Cannot assign "<django.db.models.fields.related.ForeignKey>": "Worry.user" must be a "User" instance. 我试图将当前用户的id分配给我刚刚创建的对象。 这是我的models.py的一部分: from django.contrib.auth.models import User from django.forms import ModelForm from django.db import models class UserForm (ModelForm) : class Me

csrf token Follow up

Hello and thank you in advance. This is a follow up question from the following thread (not sure if I should have posted there or started a new thread...: CSRF token missing or incorrect even though I have {% csrf_token %} I am not sure what I need to do with the code to make csrfContext work. I am trying to use ModelForm to collect data to a model and write it to a MYSQL table. I am getti

csrf令牌跟进

你好,并提前谢谢你。 这是来自以下线程的后续问题(不知道我是否应该在那里发布或开始新线程...: 即使我拥有{%csrf_token%},CSRF令牌缺失或不正确 我不知道我需要用代码来完成csrfContext的工作。 我正在尝试使用ModelForm将数据收集到模型并将其写入MYSQL表。 我收到错误: Reason given for failure: CSRF token missing or incorrect. 代码如下: from django.shortcuts import render_to_response

Django low level cache views

I have an index view which validates a form containing various data. Even though the thankyou.html page doesn't have complex calculations to kill the server, i would like to render aa slighlty different html page if thankyou.html is already low level cached. To tell you the truth, I don't know what key to pass it... Here is the code. def index(request): form = UserForm() message =

Django低级缓存视图

我有一个索引视图来验证包含各种数据的表单。 尽管thankyou.html页面没有复杂的计算来终止服务器,但是如果thankyou.html已经低级缓存,我想渲染一个不同的html页面。 说实话,我不知道通过它的关键是什么...这是代码。 def索引(请求): form = UserForm() message ='数据不正确!' 如果request.method =='POST': form = UserForm(request.POST) 如果form.is_valid(): 尝试: User.

custom autocomplete for cmd module using raw

I have a project using Python 2.7, with the Cmd Module. I have tab complete working with the existing commands using the complete_* methods. However, I would like to extend that a little, for instance we have a command called 'ask'. Rather than having everything input on a single line, I have a few questions following using raw_input. ie def do_ask(self,args): name = raw_i

自定义自动完成cmd模块使用raw

我有一个使用Python 2.7和Cmd模块的项目。 我使用complete_ *方法完成了使用现有命令的选项卡。 但是,我想稍微扩展一下,例如我们有一个叫做'ask'的命令。 在使用raw_input之后,我有一些问题,而不是将所有内容都放在一行上。 即 def do_ask(self,args): name = raw_input('What is your name: ') bird = raw_input('What is your favourite Bird: ') reptile = raw_input('What is the best r

Regarding return value of python select.select call

In python's SocketServer.py code, I find the following code. r, w, e = _eintr_retry(select.select, [self], [], [], poll_interval) if self in r: self._handle_request_noblock() Is the above if statement necessary? Since only "self" is being passed to select call, I do not expect other file descriptor to be present in the returned list of file descriptor. The reason I am askin

关于python select.select调用的返回值

在python的SocketServer.py代码中,我找到下面的代码。 r, w, e = _eintr_retry(select.select, [self], [], [], poll_interval) if self in r: self._handle_request_noblock() 上面的if语句是否必要? 由于只有“自我”被传递给选择调用,我不希望其他文件描述符出现在返回的文件描述符列表中。 我问这个问题的原因是,我是否应该遵循上面的风格,或者像下面这样的东西就足够了? r, w, e = select.select( [self], [],

input() and sys.stdin misbehaves on CTRL

I am trying to detect a KeyboardInterrupt exception when CTRL-C is pressed during a raw_input() prompt. Normally the following code works just fine to detect the command: try: input = raw_input("Input something: ") except KeyboardInterrupt: do_something() The problem comes when trying to intercept the input from sys.stdin. After adding some code in between raw_input() and sys.stdin, t

input()和sys.stdin在CTRL上行为不当

我正在尝试在raw_input()提示符期间按CTRL-C时检测到KeyboardInterrupt异常。 通常,以下代码可以很好地检测命令: try: input = raw_input("Input something: ") except KeyboardInterrupt: do_something() 尝试拦截来自sys.stdin的输入时出现问题。 在raw_input()和sys.stdin之间添加一些代码之后,CTRL-C命令现在会导致两个例外:EOFError,后跟KeyboardInterrupt后面的一行或两行。 这是用于测试的代码: i

server script hangs until I press [enter]

I have a basic client-server script in Python using sockets. The server binds to a specific port and waits for a client connection. When a client connects, they are presented with a raw_input prompt that sends the entered commands to a subproc on the server and pipes the output back to the client. Sometimes when I execute commands from the client, the output will hang and not present me with t

服务器脚本挂起,直到我按[enter]

我使用套接字在Python中有一个基本的客户端服务器脚本。 服务器绑定到特定的端口并等待客户端连接。 当客户端连接时,它们会显示一个raw_input提示符,用于将输入的命令发送到服务器上的一个子进程并将输出返回给客户端。 有时,当我从客户端执行命令时,输出会挂起,并且不会显示raw_input提示符,直到我按[enter]键。 起初我认为这可能是一个缓冲区问题,但是当我使用带有小输出的命令时(如'clear'或'ls'

completion in cmd.Cmd, when sys.stdout has been replaced

Currently, I have an application which uses the cmd.Cmd module for the command line interface, tab-completion works perfectly. Now, I'd like to replace sys.stdout , with another object (For example, in order to capture what's being written.) Following snippet should be completely transparent in theory, as every get/set operation to the Std object is redirected to the actial sys.__stdo

在cmd.Cmd中完成时,sys.stdout已被替换

目前,我有一个使用cmd.Cmd模块作为命令行界面的应用程序,tab-completion非常完美。 现在,我想用另一个对象替换sys.stdout (例如,为了捕获正在写入的内容)。 以下片段理论上应该是完全透明的,因为对Std对象的每个get / set操作都会重定向到sys.__stdout__ 。 class Std(object): def __getattribute__(self, name): if name in ('__getattribute__', '__setattr__'): return object.__getattr

input() and input() in python3.x?

python3.x中raw_input()和input()之间有什么区别? The difference is that raw_input() does not exist in Python 3.x, while input() does. Actually, the old raw_input() has been renamed to input() , and the old input() is gone, but can easily be simulated by using eval(input()) . (Remember that eval() is evil, so if try to use safer ways of parsing your input if possible.) In Python 2 , raw_input(

输入()和输入()在python3.x?

python3.x中raw_input()和input()之间有什么区别? 不同的是, raw_input()在Python 3.x中不存在,而input()却存在。 实际上,旧的raw_input()已被重命名为input() ,而旧的input()已不存在,但可以通过使用eval(input())轻松进行模拟。 (请记住, eval()是邪恶的,所以如果可能,尝试使用更安全的方式解析输入。) 在Python 2中 , raw_input()返回一个字符串, input()尝试将输入作为Python表达式运行。 由于获得一个