如何在调用is_valid()方法后更改表单字段值?
u_id在我验证数据后,我试图改变字段form.is_valid(这是必需的).我可以改变数据,甚至可以在数据中显示HttpResponse,但我无法将其写入我的Postgresql数据库.有任何想法吗?
class ProductForm(forms.ModelForm):
class Meta:
model = Product
class Product(models.Model):
p_name = models.CharField(max_length=30)
u_id = models.CharField(max_length=80)
def uploadImage(request):
if request.method == 'POST':
form1 = ProductForm(request.POST, prefix="product")
if form.is_valid() and form1.is_valid():
form1.cleaned_data['uid']='12134324231'
form1.save()
return HttpResponse(form1.cleaned_data['p_name'])
return render_to_response('upload.html', {'form': form, 'form1': form1}, RequestContext(request))
Run Code Online (Sandbox Code Playgroud) 我对c ++很陌生,我的问题可能有一个非常简单的解决方案,但我自己无法弄明白.
假设我有两个字节数组a和b.每个都包含六个字节.现在我想介绍一个新的数组c,它应该包含a和b.
这是我尝试的方式:
byte a[] = {B11111111, B10010000, B10011000, B10010100, B10010010, B11110001};
byte b[] = {B11111111, B10000001, B10000001, B10000001, B10000001, B11111111};
byte c[2][6] = {{a},{b}};
Run Code Online (Sandbox Code Playgroud)
编译器给我以下错误:
invalid conversion from 'byte' to 'byte'
Run Code Online (Sandbox Code Playgroud) 使用urllib2可以对URL请求进行抽象.这样您就可以在实际发出请求之前对请求主体执行操作.
像这样的东西,例如:
def authentication(self, req):
signup = md5(str(req.get_data())).hexdigest()
req.add_header('Authorization', signup)
return urllib2.urlopen(req)
def some_request(self):
url = 'http://something'
req = urllib2.Request(url)
response = authentication(req)
return json.loads(response.read())
Run Code Online (Sandbox Code Playgroud)
我想使用python-requests而不是urllib2.我怎样才能实现上面使用它的例子呢?