当重复条目尝试保存时,我想更改默认错误消息,因为它们应该是唯一的,即unique=True.很像这样:
email = models.EmailField(unique=True, error_messages={'unique':"This email has already been registered."})
Run Code Online (Sandbox Code Playgroud)
但是,unique在上面的情况下是猜测,并不起作用.我也无法找出错误的名称实际上是什么.有谁知道正确的名字?
请注意,此验证是模型级别,而不是表单验证.
编辑:更多信息,目前显示当前错误消息form.errors:
[model_name] with this [field_label] already exists
Run Code Online (Sandbox Code Playgroud)
哪个不是非常用户友好,所以我想覆盖它...
我有一个django应用程序,目前使用用户可以下载的画布生成pdfs.我创建一个StringIO缓冲区,做一些东西,然后发送调用response.write.
# Set up response
response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=menu-%s.pdf' % str(menu_id)
# buffer
buff = StringIO()
# Create the pdf object
p = canvas.Canvas(buff)
# Add some elements... then
p.showPage()
p.save()
# Get the pdf from the buffer and return the response
pdf = buff.getvalue()
buff.close()
response.write(pdf)
Run Code Online (Sandbox Code Playgroud)
我现在想用platypus和SimpleDocTemplate构建我的pdf并编写了这个
# Set up response
response = HttpResponse(mimetype='application/pdf')
pdf_name = "menu-%s.pdf" % str(menu_id)
response['Content-Disposition'] = 'attachment; filename=%s' % pdf_name
menu_pdf = SimpleDocTemplate(pdf_name, rightMargin=72,
leftMargin=72, topMargin=72, bottomMargin=18)
# container for pdf …Run Code Online (Sandbox Code Playgroud) 我创建了一个本地分支
$ git branch group_contact_form
Run Code Online (Sandbox Code Playgroud)
我提交了一些更改,然后将分支发送到远程,如下所示:
$ git push origin group_contact_form
Run Code Online (Sandbox Code Playgroud)
我很乐意继续推送提交并$ git branch -a显示我的本地和远程分支
* group_contact_form
master
remotes/origin/HEAD -> origin/master
...
remotes/origin/group_contact_form
...
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用时$ git pull:
fatal: 'origin/group_contact_form' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
Run Code Online (Sandbox Code Playgroud)
我的.git/config情况如下:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = database1:/var/git/repo_name.git
[branch "master"]
remote = origin …Run Code Online (Sandbox Code Playgroud) 我有一个django网站,运行django-cms非常愉快,但现在我想用jQuery包含一些我自己喜欢的javascript.我对django很新,所以我的问题可能源于此.
Django-cms本身就使用了jQuery,所以如果我将jquery添加到标题中 - 事情会毫不奇怪地破坏rathter.如何在不影响django-cms的情况下添加自己的jQuery?
目前我的javascript文件存储在我在项目settings.py中定义的媒体根目录中,如上所述,我在标题中引用它们.
在我读到这篇文章时,这似乎是一个愚蠢的问题,但我仍然感到困惑.
编辑::一些代码
我有一个媒体根定义:
MEDIA_ROOT = os.path.join(PROJECT_PATH, 'media')
Run Code Online (Sandbox Code Playgroud)
在我的基本模板中,标题包括
<script src="/media/javascript/jquery.js" type="text/javascript"></script>
<script src="/media/javascript/application.js" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)
application.js中的Javascript可以工作,但是当django-cms的东西启动它就会中断.例如,尝试将插件添加到占位符会导致:
Uncaught TypeError: Property 'type' of object function ( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init( selector, context );
} is not a function
Run Code Online (Sandbox Code Playgroud)
我以为这是因为两个jQuerys相互冲突
::另一个编辑::我应该补充一点,我正在使用django来托管静态文件,因为它仍在开发中......