我需要在Form clean方法中验证上传的XML文件的内容,但是我无法打开该文件进行验证.它接缝,在clean方法中,文件尚未从内存(或临时目录)移动到目标目录.
例如,以下代码不起作用,因为该文件尚未移动到该目标.它仍然在内存(或临时目录)中:
xml_file = cleaned_data.get('xml_file')
xml_file_absolute = '%(1)s%(2)s' % {'1': settings.MEDIA_ROOT, '2': xml_file}
xml_size = str(os.path.getsize(xml_file_absolute))
Run Code Online (Sandbox Code Playgroud)
当我查看"cleaning_data"变量时,它会显示:
{'xml_file': <InMemoryUploadedFile: texting.nzb (application/octet-stream)>}
Run Code Online (Sandbox Code Playgroud)
cleaned_data.get('xml_file') 只返回"texting.nzb"作为字符串.
是否有另一种方法来访问内存(或临时目录)中的文件?
同样,这是我的Form的clean方法,它绑定到默认的管理视图.我一次又一次地被告知所有验证都应该在表单中处理,而不是视图.正确?
Maven Archetypes是"模板",通过它您可以快速生成给定框架或项目类型的运行示例.我正在尝试编译当前在网上活动的所有Maven原型目录的列表.
关于原型的知识存储在目录中.
目录是xml文件.
Archetype插件捆绑了内部目录.默认情况下使用此选项.
Archetype插件可以使用本地文件系统和HTTP连接中的目录.
到目前为止,我已经收集了这个发布目录的存储库列表,但是很想知道是否有人知道更多:
mvn archetype:generate
-DarchetypeCatalog=local
-DarchetypeCatalog=remote
-DarchetypeCatalog=http://repo.fusesource.com/maven2
-DarchetypeCatalog=http://cocoon.apache.org
-DarchetypeCatalog=http://download.java.net/maven/2
-DarchetypeCatalog=http://myfaces.apache.org
-DarchetypeCatalog=http://tapestry.formos.com/maven-repository
-DarchetypeCatalog=http://scala-tools.org
-DarchetypeCatalog=http://www.terracotta.org/download/reflector/maven2/
Run Code Online (Sandbox Code Playgroud)
链接到相同的:1)FuseSource 2) Cocoon 3)Java.net 4)MyFaces 5)Tapestry 6)Scala目录 7)Terracotta目录
您会注意到,如果存储库实际发布了原型目录(以上所有内容),您将获得所有选项的UI提示archetype-catalog.xml.例如:
mvn archetype:generate -DarchetypeCatalog=http://scala-tools.org
[INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0)
Choose archetype:
1: http://scala-tools.org -> scala-archetype-simple (A simple scala project)
2: http://scala-tools.org -> lift-archetype-blank (A blank/empty liftweb project)
3: http://scala-tools.org -> lift-archetype-basic (A basic liftweb project (with DB, css, ...))
Choose a …Run Code Online (Sandbox Code Playgroud) 请查看下面的代码并帮助我弄清楚我的Web服务代码中出了什么问题.我想建立一个可以使用JSONP使用的asp.net Web服务.我在客户端使用Jquery来访问该站点.即使在设置了适当的属性后,我的Web服务仍然会发出xml,因为aynch调用失败了.
网络服务
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {
public WebService () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
[ScriptMethod(ResponseFormat= ResponseFormat.Json, XmlSerializeString=false, UseHttpGet=true)]
public string HelloWorld(int id, string __callback) {
return __callback + "({message: 'Hello World'})";
}
}
Run Code Online (Sandbox Code Playgroud)
Web服务响应:
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">test({message: 'Hello World'})</string>
Run Code Online (Sandbox Code Playgroud)
Web.Config中:
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false"
type="System.Web.Script.Services.ScriptHandlerFactory,
System.Web.Extensions, Version=3.5.0.0,
Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> …Run Code Online (Sandbox Code Playgroud) 我知道有一个更优雅/有效的方法(在php中我会使用foreach)但是使用jQuery我如何走JSON响应的var/val对并填充与字段名称相同id的表单字段在JSON响应中?
这是我的JSON响应:
[{"field":"svendor_name","value":"Vendor Name Inc."},{"field":"svendor_addr1","value":"1234 Vendor Lane."},{"field":"svendor_addr2","value":"Suite 100"},{"field":"svendor_city"
,"value":"Vendorville"},{"field":"svendor_state","value":"CA"},{"field":"svendor_zip","value":"90210"},{"field"
:"svendor_phone","value":"800-555-1234"}]
Run Code Online (Sandbox Code Playgroud)
这是我填充表单的jQuery代码:
$(document).ready(function()
{
$('#svendor_name').bind("change", function()
{
var svendor = $("#svendor_name").val();
svendor = svendor.replace(/&/g, '*');
$.getJSON("get_vendors.php?sname=" + svendor,
function(data)
{
$.each(data,
function(i, item)
{
if(item.field == "svendor_name")
{
$("#svendor_name").val(item.value);
}
else if(item.field == "svendor_addr1")
{
$("#svendor_addr1").val(item.value);
}
else if(item.field == "svendor_addr2")
{
$("#svendor_addr2").val(item.value);
}
else if(item.field == "svendor_city")
{
$("#svendor_city").val(item.value);
}
else if(item.field == "svendor_state")
{
$("#svendor_state").val(item.value);
}
else if(item.field == "svendor_zip")
{
$("#svendor_zip").val(item.value);
}
else if(item.field == "svendor_phone")
{
$("#svendor_phone").val(item.value); …Run Code Online (Sandbox Code Playgroud) 我一直在寻找一段时间来找到完成以下系统的解决方案.
我想建立一个PHP系统,比如说domainA.在这个域名上,我将允许管理员"创建"一个新网站.该网站仅包含文本片段,这些文本都存储在数据库中.这个,我知道怎么做.
但是,现在我想让访问域名B的访问者无形地重定向到例如domainA.com/gateway.php?refdomain=domainB&page=xxx或类似内容.我有一个模糊的想法,这应该由.htaccess完成,但我真的不知道如何以最简单的方式做到这一点.例如,如果在domainB上有一些POST或GET请求,这应该继续工作.此外,链接到http://www.domainB.com/test.gif的图片也应该以www.domainA.com的形式无形加载.
我也知道有一些CMS系统(例如drupal)允许这个功能,所以有可能,我只是不知道如何.
感谢您提出任何建议,指出我正确的方向,亲切的问候,数字
我希望我的Grails网络应用程序能够为每个到达最终用户的异常发送电子邮件.
基本上我正在寻找一种优雅的方式来实现相当于:
try {
// ... all logic/db-access/etc required to render the page is executed here ...
}
catch (Exception e) {
sendmail("exception@example.com", "An exception was thrown while processing a http-request", e.toString);
}
Run Code Online (Sandbox Code Playgroud) 在给定分配给其SelectCommand属性的存储过程的名称的情况下,是否有一种从SqlDataSource获取预期参数列表的合理方法?
ASP.NET DropDownList具有属性Enabled="false",但是可以jQuery将属性设置为Enabled="true"?
我有一个用于重置路由器的书签.我只需要访问并让页面完成加载,然后我的路由器开始重置.
javascript:(function(){w=window.open("http://192.168.0.1/goform/formReboot","","width=1,height=1");self.focus();window.onload=w.close();})();
Run Code Online (Sandbox Code Playgroud)
但它会在弹出窗口中打开.
我的新想法是使用javascript bookmaklet动态地将隐藏的iframe附加到我正在使用的页面,然后在隐藏的iframe中打开url.这甚至可能吗?
我愿意就如何做到这一点提出更好的建议.
我想实现一个方法,它接受一个Objectas参数,将它转换为任意类型,如果失败则返回null.这是我到目前为止所拥有的:
public static void main(String[] args) {
MyClass a, b;
a = Main.<MyClass>staticCast(new String("B"));
}
public static class MyClass {
}
public static <T> T staticCast(Object arg) {
try {
if (arg == null) return null;
T result = (T) arg;
return result;
} catch (Throwable e) {
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,类强制转换异常永远不会被抛出/捕获到staticCast()函数体中.似乎Java编译器生成了一个函数,String staticCast(Object arg)在该函数中你有一条线,String result = (String) arg;即使我明确地说模板类型应该是MyClass.有帮助吗?谢谢.
jquery ×3
asp.net ×2
java ×2
javascript ×2
.htaccess ×1
.net ×1
bookmarklet ×1
casting ×1
django ×1
exception ×1
generics ×1
grails ×1
gsp ×1
html ×1
iframe ×1
json ×1
jsonp ×1
maven-2 ×1
maven-plugin ×1
php ×1
python ×1
router ×1
sql-server ×1
web-services ×1