我有一个期待两种形式的模板页面.如果我只使用一个表单,那么就像这个典型的例子一样好:
if request.method == 'POST':
form = AuthorForm(request.POST,)
if form.is_valid():
form.save()
# do something.
else:
form = AuthorForm()
Run Code Online (Sandbox Code Playgroud)
但是,如果我想使用多个表单,我如何让视图知道我只提交其中一个表单而不是另一个表单(即它仍然是request.POST但我只想处理提交的表单事情)吗?
这是该解决方案基于这样的答案expectedphrase和bannedphrase是不同形式和不同的提交按钮的名称expectedphraseform和bannedphraseform是形式.
if request.method == 'POST':
if 'bannedphrase' in request.POST:
bannedphraseform = BannedPhraseForm(request.POST, prefix='banned')
if bannedphraseform.is_valid():
bannedphraseform.save()
expectedphraseform = ExpectedPhraseForm(prefix='expected')
elif 'expectedphrase' in request.POST:
expectedphraseform = ExpectedPhraseForm(request.POST, prefix='expected')
if expectedphraseform.is_valid():
expectedphraseform.save()
bannedphraseform = BannedPhraseForm(prefix='banned')
else:
bannedphraseform = BannedPhraseForm(prefix='banned')
expectedphraseform = ExpectedPhraseForm(prefix='expected')
Run Code Online (Sandbox Code Playgroud) 很长一段时间我都有这个错误,但无法弄清楚:
渲染时捕获TypeError:强制转换为Unicode:需要字符串或缓冲区,找到NoneType
当我尝试在我的一个模型上添加或修改时,它发生在管理员中(显示工作正常)
这是模型:
class PS(models.Model):
id_ps = models.IntegerField(null=True)
client = models.ForeignKey(Client, null=True, blank=True)
nom_du_site = models.CharField(max_length=250)
rue_livraison = models.TextField(null=True)
complement_adresse = models.TextField(null=True)
code_postal_livraison = models.CharField(max_length=50, null=True)
ville_livraison = models.CharField(max_length=200, null=True)
pays_livraison = models.CharField(max_length=200, null=True)
distributeur = models.CharField(max_length=50, null=True)
tarif = models.CharField(max_length=250, null=True)
type_tarif = models.CharField(max_length=50, null=True)
type_installation = models.CharField(max_length=50, null=True)
def __unicode__(self):
return self.nom_du_site
@property
def pce(self):
try:
return PCE.objects.filter(ps=self)[0]
except IndexError:
return
#
def get_pce(self):
from pce.models import PCE
return PCE.objects.filter(ps=self).exclude(frequence='6M')
#
def get_pce_6m(self):
from pce.models import PCE …Run Code Online (Sandbox Code Playgroud) 我是ExtJS 4的新手,需要一些帮助来理解它是如何Ext.define工作的.
实际上我想做的是类似于门户网站示例中的portlet,在我的应用程序中,我需要在我的不同选项卡中添加很多对象,所以为了组织我的代码而不是只有一个非常大的脚本,我想在一个单独的文件中定义我需要的每个组件,然后在需要时在主脚本中调用它(我将主要使用这些示例,这就是为什么我想知道它是如何Ext.define工作的所以我可以调整这些示例并使它们成为可能以我想要的方式工作).
我希望我很清楚.
并提前感谢您的帮助.
runserver当我在运行虚拟环境时尝试任何项目时出现此错误(workon django1.2)
错误 :
ImportError: cannot import name "urandom"
Run Code Online (Sandbox Code Playgroud)
在研究了这个问题之后我发现了这个:
警告Python错误修复版本2.6.8,2.7.3,3.1.5和3.2.3包含一个更改,该修改将导致"导入随机"失败,并且在使用早期版本的Unix主机上创建的任何virtualenv上"无法导入名称urandom" Python 2.6/2.7/3.1/3.2,如果底层系统Python升级了.这是因为virtualenv使用系统Python的标准库但包含自己的Python解释器副本,因此升级到系统Python会导致Python解释器版本与标准库版本不匹配.可以通过删除$ ENV/bin/python并使用升级的Python在同一目标目录上重新运行virtualenv来解决此问题.
但跑步ENV/bin/python给了我:
bash: ENV/bin/python: No file or directory of this type
Run Code Online (Sandbox Code Playgroud)
我在哪里可以找到我的virtualen目录?
我对virtualenvs了解甚少,所以请耐心等待
谢谢
我正在尝试基于PyAPN实现iphone的推送通知
当我在本地运行它但它阻止并提示我手动输入密码短语,直到我这样做才行
我不知道如何设置它以便在没有提示的情况下工作
这是我的代码:
from apns import APNs, Payload
import optparse
import os
certificate_file = here(".." + app.fichier_PEM.url )
token_hex = '0c99bb3d077eeacdc04667d38dd10ca1a'
pass_phrase = app.mot_de_passe
apns = APNs(use_sandbox=True, cert_file= certificate_file)
payload = Payload(alert = message.decode('utf-8'), sound="default", badge=1)
apns.gateway_server.send_notification(token_hex, payload)
# Get feedback messages
for (token_hex, fail_time) in apns.feedback_server.items():
print "fail: "+fail_time
Run Code Online (Sandbox Code Playgroud) python django push-notification apple-push-notifications django-1.2
我想在图表中添加标题,例如在仪表示例或饼图中.我想在图表下方或顶部显示标题.这可能吗?我一直在寻找并且找不到任何关于此的信息.如果是这样,任何提示要分享?它会是这样的
编辑:我发现有一个属性可以为 Ex.draw包中的标题或任何标签创建文本精灵.但我无法理解如何使用它..
anybdy在这里做了同样的事情吗?
我需要删除所有边框.我已经添加border:false但是它不起作用.
请注意,我希望它具有此蓝色背景,所以我正在使用frame : true.
region: 'north',
split: true,
border: false,
height: 115,
layout: 'border',
items: [ {///Account info
xtype: 'form',
region: 'east',
border: false,
frame: true,
//height: 100,
width: 500, //'49%',//anchor : '50%',
layout: 'column',
items: [
{ columnWidth: .5,
border: false,
frame: true,
defaults: { labelStyle: 'font-size:9px' },
items: [{
xtype: 'displayfield',
fieldLabel: 'Customer',
value: '<span style="color:blue;font-size:9px">IBM</span>'
}, {
xtype: 'displayfield',
fieldLabel: 'Subscription',
value: '<span style="color:blue;font-size:9px">On demand</span>'
}, {
xtype: 'displayfield',
fieldLabel: …Run Code Online (Sandbox Code Playgroud) 我有一个在提交时不起作用的铭文表格
我收到此错误:
**之后的reverse()参数必须是映射,而不是str
这是我的看法:
def inscription(request, seance_id):
seance = get_object_or_404(Variant, id=seance_id)
inscription_config = {'form_class': InscriptionForm,
'extra_context': {'seance': seance}}
return create_object(request, **inscription_config)
Run Code Online (Sandbox Code Playgroud)
我的表格:
class InscriptionForm(forms.ModelForm):
class Meta:
model = Inscription
def clean(self):
cleaned_data = self.cleaned_data
email = cleaned_data.get("mail")
mail_confirmation = cleaned_data.get("mail_confirmation")
if email != mail_confirmation:
raise forms.ValidationError("Les deux adresses mails doivent correspondre")
return cleaned_data
Run Code Online (Sandbox Code Playgroud)
似乎在return语句中触发错误的是**inscription_config
但我不明白为什么,从昨天起我一直在寻找
编辑
Environment:
Request Method: POST
Request URL: http://127.0.0.1:8039/formations/inscription/1/
Django Version: 1.2.5
Python Version: 2.7.2
Installed Applications:
['django.contrib.auth',
'django.contrib.comments',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
'ckeditor', …Run Code Online (Sandbox Code Playgroud) 1- 如何在创建网格时将列设置为排序? 然后在重新加载网格时,它会自动利用那种排序来适当地显示记录.(没有我对它进行陈述)这可以在网格上完成,因此它独立于底层数据存储吗?
2- 如何更改网格列中显示的日期格式?
我的数据呈现这样的日期/Date(1316020760837+0000)/
我尝试使用,renderer: Ext.util.Format.dateRenderer('m/d/Y'),// format: 'm d Y'
但它给了我NaN/NaN/NaN
任何帮助,将不胜感激.谢谢
我使用iTextSharp生成了一个pdf,当它创建时,它会自动保存在我的代码中提供的位置,而不是在客户端的服务器上,当然也没有告诉用户任何东西.
我需要将它发送给客户端,我需要提示一个对话框询问用户他想要保存他的pdf的位置.
我该怎么办?
这是我的pdf代码:
using (MemoryStream myMemoryStream = new MemoryStream())
{
Document document = new Document();
PdfWriter PDFWriter = PdfWriter.GetInstance(document, myMemoryStream);
document.AddHeader("header1", "HEADER1");
document.Open();
//..........
document.Close();
byte[] content = myMemoryStream.ToArray();
// Write out PDF from memory stream.
using (FileStream fs = File.Create(HttpContext.Current.Server.MapPath("~\\report.pdf")))
{
fs.Write(content, 0, (int)content.Length);
}
Run Code Online (Sandbox Code Playgroud)
编辑
这是我想要http://examples.extjs.eu/?ex=download的结果示例
感谢您的回复,我修改了我的代码:
HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.AppendHeader( "Content-Disposition", "attachment; filename=test.pdf");
using (MemoryStream myMemoryStream = new MemoryStream())
{
Document document = new Document();
PdfWriter PDFWriter = PdfWriter.GetInstance(document, myMemoryStream);
document.AddHeader("Content-Disposition", "attachment; filename=wissalReport.pdf");
document.Open(); …Run Code Online (Sandbox Code Playgroud)