假设我在保存代码中.如何获取对象的模型名称或内容类型,并使用它?
from django.db import models
class Foo(models.Model):
...
def save(self):
I am here....I want to obtain the model_name or the content type of the object
Run Code Online (Sandbox Code Playgroud)
这段代码有效,但我必须知道model_name:
import django.db.models
from django.contrib.contenttypes.models import ContentType
content_type = ContentType.objects.get(model=model_name)
model = content_type.model_class()
Run Code Online (Sandbox Code Playgroud) 我request.path用来获取当前的URL.例如,如果当前URL是"/ test/foo/baz",我想知道它是否以字符串序列开头,让我们说/ test.如果我尝试使用:
{% if request.path.startswith('/test') %}
Test
{% endif %}
Run Code Online (Sandbox Code Playgroud)
我收到一个错误,说它无法解析表达式的其余部分:
Could not parse the remainder: '('/test')' from 'request.path.startswith('/test')'
Request Method: GET
Request URL: http://localhost:8021/test/foo/baz/
Exception Type: TemplateSyntaxError
Exception Value:
Could not parse the remainder: '('/test')' from 'request.path.startswith('/test')'
Exception Location: C:\Python25\lib\site-packages\django\template\__init__.py in __init__, line 528
Python Executable: C:\Python25\python.exe
Python Version: 2.5.4
Template error
Run Code Online (Sandbox Code Playgroud)
一种解决方案是创建自定义标签来完成工作.还有其他东西可以解决我的问题吗?使用的Django版本是1.0.4.
Save按下该按钮时,应验证actionsDialog中的数据.如果输入了所需信息并且有效,则会显示名为reasonDialog的第二个对话框.
使用返回错误消息列表的方法完成对已保存对象的非JSF验证.我的情况是验证失败,错误消息与FacesMessage一起显示.我应该如何objectsBean.validate触发if else子句oncomplete?
<p:dialog id="actionsDialog" widgetVar="actionsDialog" dynamic="true"
resizable="false" width="800" modal="true">
<ui:include src="/WEB-INF/flows/custom-flow/genericObject.xhtml"/>
<f:facet name="footer">
<p:commandButton value="Save" update="msgs"
oncomplete="if (args.validationFailed) {reasonDialog.hide()} else {reasonDialog.show()}"
actionListener="#{objectsBean.validate}"/>
<p:commandButton value="Cancel" immediate="true" oncomplete="actionsDialog.hide()" />
</f:facet>
</p:dialog>
Run Code Online (Sandbox Code Playgroud) 我在页面上有一个按钮,可以通过AJAX请求刷新我的数据表.像这样的东西:
<h:form id="datatable">
<p:dataTable/>
</h:form>
<p:commandButton update=":datatable">
Run Code Online (Sandbox Code Playgroud)
这一切都很好,但是当表刷新时,它会恢复到不排序任何东西,同时仍然显示它是基于前一个值进行排序.换句话说,标题仍然突出显示,箭头仍指向排序方向,但实际上没有执行排序.显然这并不理想.
理想情况下,我希望组件在视图状态中保持其排序顺序,然后在AJAX请求期间提交适当的参数(以便正确定义排序).我错过了一个参数或什么?还有其他人有这个问题吗?
从表格预期排序时我可以看出它发布了以下选项:
<componentID>_sortDir
<componentID>_sortKey
<componentID>_sorting
<componentID>_updateBody
Run Code Online (Sandbox Code Playgroud)
当我刷新表单时,这不会发生.如果我只刷新表格也不会发生这种情况(我想通过直接更新组件可以解决问题).有没有办法让表格正确刷新?
当电子邮件地址无效时,显示的消息是"无效的电子邮件.无效的电子邮件.".我知道该消息有两部分:摘要和细节.我需要这两个,但我希望每个都有不同的信息.如何更改邮件以显示"无效的电子邮件:请输入有效的电子邮件地址"?
<p:messages showDetail="true" autoUpdate="true" closable="true" />
<h:panelGrid columns="2">
<h:outputText value="#{label.email}: *" />
<p:inputText required="true" value="#{userWizard.emailAddress}"
validatorMessage="#{label.invalidEmail}" label="#{label.email}">
<f:validateRegex pattern="^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$">
</f:validateRegex>
</p:inputText>
</h:panelGrid>
Run Code Online (Sandbox Code Playgroud) 可能的重复:
如何分析 Python 脚本?
您知道哪些可视化工具,类似于 Java 的 JProfiler,可以分析 Python 应用程序的性能?
如何配置GRADLE_USER_HOME选项?我的Windows用户名包含一个空格(C:\Users\Baz Foo),我认为构建失败是因为这个.
E:\workspace-sts-3.0.0.RELEASE\agweb\ag-client\ag-shared\build\classes\main
error: Class com.acme.client.conn.rmi.SessionRMIImpl not found.
error: Class Foo\.gradle\caches\artifacts-13\filestore\xerces\xercesImpl\2.1
0.0\jar\9161654d2afe7f9063455f02ccca8e4ec2787222\xercesImpl-2.10.0.jar not found
.
error: Class Foo\.gradle\caches\artifacts-13\filestore\xml-apis\xml-apis\1.4
.01\jar\3789d9fada2d3d458c4ba2de349d48780f381ee3\xml-apis-1.4.01.jar;C:\Users\Baz
not found.
error: Class Foo\.gradle\caches\artifacts-13\filestore\provided\jbpm\3.0.4\j
ar\f2a9f8f32e59b335e069b5444f6c36a30abf0845\jbpm-3.0.4.jar;C:\Users\Baz not fou
nd.
error: Class Foo\.gradle\caches\artifacts-13\filestore\log4j\log4j\1.2.16\bu
ndle\7999a63bfccbc7c247a9aea10d83d4272bd492c6\log4j-1.2.16.jar;C:\Users\Baz not
found.
5 errors ...
Run Code Online (Sandbox Code Playgroud)
我已经添加了一个环境变量GRADLE_USER_HOME并将其设置为C:\Users\Baz Foo\.gradle并尝试了--gradle-user-home="C:\Users\Baz Foo\.gradle"但没有一个工作.
有谁知道是否有适用于Windows,Mac和Linux的文本到语音的Python库?
我有两个数据表,有两种形式,forma和formg.每个表单里面都有一个p:dataTable,groupsa和groupsg.在每个DataTable有显示图像(自定义列h:graphicImage)称为蚕豆和favg.
单击图像时,将更新来自其他数据表的图像.
<p:ajax event="click" listener="#{agent.toogleFavorite}"
update="fava, :formg:groupsg:favg" />
Run Code Online (Sandbox Code Playgroud)
没有冒号,我得到一个例外:
javax.faces.FacesException: Cannot find component with identifier "forma:agentsa:fava" referenced from "groupsg:0:favg".
Run Code Online (Sandbox Code Playgroud)
formg:groupsg:favg和:formg:groupsg:favg有什么区别?
我使用的是JSF2.0和PrimeFaces 3.4.
ui:include标签是如何实现的?我在哪里可以找到它的实现(源代码)?
java ×5
jsf ×4
primefaces ×4
python ×4
ajax ×2
django ×2
build ×1
content-type ×1
datatable ×1
gradle ×1
growlnotify ×1
jprofiler ×1
jsf-2 ×1
linux ×1
macos ×1
messages ×1
performance ×1
sorting ×1
templates ×1
uiinclude ×1
url ×1
validation ×1
windows ×1