我有一个URL模式映射到我的Django App中的自定义视图类,如下所示:
url( r'^run/(?P<pk>\d+)/$', views.PerfRunView.as_view( ))
Run Code Online (Sandbox Code Playgroud)
问题是,我无法弄清楚如何从视图类中的URL模式字符串访问'pk',以便我可以根据其数据库ID检索特定的模型对象.我用Google搜索,查看了Django文档,搜索了Stack Overflow,我找不到满意的答案.
有人能告诉我吗?
我昨晚在PC上使用VS 2010 Ultimate开发了一个WPF项目.
我刚刚在我的上网本上用VS C#2010 Express打开了它.
当我尝试运行它时,我抛出了一个XAML Parse异常,告诉我该行:
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Run Code Online (Sandbox Code Playgroud)
是问题.我看不出它的问题,我从来没有改变它,看起来它应该是它应该是什么.
错误:
'The invocation of the constructor on type 'WpfApplication1.MainWindow' that matches the specified binding constraints threw an exception.' Line number '3' and line position '9'.
Run Code Online (Sandbox Code Playgroud)
完整的XAML:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Camera" Height="550" Width="826" Background="#ddd" ResizeMode="NoResize" WindowStyle="None" MouseLeftButtonDown="Window_MouseLeftButtonDown" BorderBrush="#FF8D8D8D" BorderThickness="2" >
<Window.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<ContentPresenter
Margin="{TemplateBinding Control.Padding}"
HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}"
ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
RecognizesAccessKey="True"
Content="{TemplateBinding ContentControl.Content}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources> …
Run Code Online (Sandbox Code Playgroud) 我正在开发一个React应用程序并尝试让Chartjs从其npm包中导入它.以下是初始化代码:
//in my constructor
this.usageChart = null;
//in componentDidMount
let chartContext = document.getElementById("proc_usage");
let initialDataIdle = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100];
let initialDataOther = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
console.log("Creating chart");
this.usageChart = new Chart(chartContext, {
type: "line",
data: {
datasets: [
{ label: "User", fill: true, data: initialDataOther, backgroundColor: "rgba(244, 143, 177, 0.8)" },
{ label: "System", fill: true, data: initialDataOther, backgroundColor: "rgba(255, 235, 59, 0.8)" },
{ label: …
Run Code Online (Sandbox Code Playgroud) 好的,所以我有一个程序可以将一些特定的数据输出到制表符分隔的变量文件中.
我一直在使用Excel打开并查看文件内容,但是我发现excel坚持要锁定它打开的每个文件都非常烦人,因为如果我在Excel中打开文件我的程序会崩溃...但我真的很喜欢每次运行程序后数据都要整齐地更新,所以我不必一直关闭并重新打开文件.
因此,我决定使用Javascript解析文件并将其显示在html表中是最简单的,而且确实如此.我立刻把东西撞到了一起.现在,如果我将文件保留在显示器上,我的程序不会崩溃,但是,它仍然不会更新......我每次都必须打开新生成的文件.
所以,我想知道是否有一种机制可以通过其他进程以某种方式通知我的Javascript对文件的更改?我知道这不太可能,但我想避免简单地轮询文件,原因很明显.
我对JS非常熟悉,但HTML5和新API对我来说都是新手.
我正在尝试安装设备到我的rails应用程序,但我得到的是这个错误消息
rails g devise:install
/Users/luketimothy/.rvm/gems/ruby-2.2.3/gems/debug_inspector-0.0.2/lib/debug_inspector.rb:6:in `require': incompatible library version - /Users/luketimothy/.rvm/gems/ruby-2.2.3/gems/debug_inspector-0.0.2/lib/debug_inspector.bundle (fatal)
from /Users/luketimothy/.rvm/gems/ruby-2.2.3/gems/debug_inspector-0.0.2/lib/debug_inspector.rb:6:in `<top (required)>'
from /Users/luketimothy/.rvm/gems/ruby-2.2.3/gems/binding_of_caller-0.7.2/lib/binding_of_caller/mri2.rb:1:in `require'
from /Users/luketimothy/.rvm/gems/ruby-2.2.3/gems/binding_of_caller-0.7.2/lib/binding_of_caller/mri2.rb:1:in `<top (required)>'
from /Users/luketimothy/.rvm/gems/ruby-2.2.3/gems/binding_of_caller-0.7.2/lib/binding_of_caller.rb:9:in `require'
from /Users/luketimothy/.rvm/gems/ruby-2.2.3/gems/binding_of_caller-0.7.2/lib/binding_of_caller.rb:9:in `<top (required)>'
from /Users/luketimothy/.rvm/gems/ruby-2.2.3/gems/web-console-2.2.1/lib/web_console.rb:1:in `require'
from /Users/luketimothy/.rvm/gems/ruby-2.2.3/gems/web-console-2.2.1/lib/web_console.rb:1:in `<top (required)>'
from /Users/luketimothy/.rvm/gems/ruby-2.2.3/gems/web-console-2.2.1/lib/web-console.rb:1:in `require'
from /Users/luketimothy/.rvm/gems/ruby-2.2.3/gems/web-console-2.2.1/lib/web-console.rb:1:in `<top (required)>'
from /Users/luketimothy/.rvm/gems/ruby-2.2.3@global/gems/bundler-1.11.2/lib/bundler/runtime.rb:77:in `require'
from /Users/luketimothy/.rvm/gems/ruby-2.2.3@global/gems/bundler-1.11.2/lib/bundler/runtime.rb:77:in `block (2 levels) in require'
from /Users/luketimothy/.rvm/gems/ruby-2.2.3@global/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `each'
from /Users/luketimothy/.rvm/gems/ruby-2.2.3@global/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `block in require'
from /Users/luketimothy/.rvm/gems/ruby-2.2.3@global/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `each'
from /Users/luketimothy/.rvm/gems/ruby-2.2.3@global/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `require'
from /Users/luketimothy/.rvm/gems/ruby-2.2.3@global/gems/bundler-1.11.2/lib/bundler.rb:99:in `require'
from /Users/luketimothy/Work/Arbitrage/config/application.rb:7:in `<top (required)>'
from /Users/luketimothy/.rvm/gems/ruby-2.2.3/gems/spring-1.6.0/lib/spring/application.rb:82:in `require'
from /Users/luketimothy/.rvm/gems/ruby-2.2.3/gems/spring-1.6.0/lib/spring/application.rb:82:in …
Run Code Online (Sandbox Code Playgroud) 部分原因是为了学习一点iOS编程,部分是因为我希望我在iPad上有一个WhatsApp客户端,我正在尝试创建一个我个人可以用作iPad的WhatsApp客户端的应用程序.它只是在UIWebView中加载web.whatsapp.com桌面站点,如下所示:
override func viewDidLoad() {
NSUserDefaults.standardUserDefaults().registerDefaults(["UserAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/601.5.17 (KHTML, like Gecko) Version/9.1 Safari/601.5.17"])
super.viewDidLoad()
self.webView.frame = self.view.bounds
self.webView.scalesPageToFit = true
// Do any additional setup after loading the view, typically from a nib.
let url = NSURL(string: "https://web.whatsapp.com")
let requestObj = NSMutableURLRequest(URL: url!)
webView.loadRequest(requestObj)
//webView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
}
Run Code Online (Sandbox Code Playgroud)
这没关系.事实上它确实加载了正确的webapp,而不是像服务器检测到移动设备时那样重定向到whatsapp主页.但是,不是向我提供登录的QR码屏幕,而是向我展示:
现在,如果我在iPad上使用Safari中的WhatsApp Web(并请求桌面版),它的工作原理非常好.如您所见,我通过设置UserAgent为我的UIWebView请求桌面站点.现在,我想知道为什么它不能在UIWebView中工作,是否可能需要设置其他标题或值以说服App在我的UIWebView控件中工作?
编辑
通过将Boris Verebsky的代码从Objective-C转换为Swift,我已经改为WKWebView.然而,虽然起初我看到的屏幕与以前一样(告诉我使用另一个浏览器),在更改它并试图让它工作后,我发现自己有一个空白的白色屏幕.什么都没有出现了.
这是我目前的完整代码:
import UIKit
import WebKit
class ViewController: UIViewController, WKNavigationDelegate {
@IBOutlet var webView: WKWebView!
override func viewDidLoad() …
Run Code Online (Sandbox Code Playgroud) 我试图在Excel VBA中使用工作表更改事件,但它似乎不起作用.
从我收集的内容来看,只需定义处理函数"Worksheet_Change"即可,就像我在这里所做的那样:
Private Sub Worksheet_Change(ByVal Target As Range)
Range("J1").Select
If Target.Address = "$J$1" And ActiveCell.Value = 1 Then
Range("B1").Select
Dim c As Integer
c = ActiveCell.Value
c = c + 1
ActiveCell.Value = c
End If
End Sub
Run Code Online (Sandbox Code Playgroud)
问题是我不确定我应该在哪里定义它.我把它放在"module1"中,这是我制作第一个宏时自动生成的.它是否正确?我对VBA很新,所以我对此还不太了解.
我正在编写一个C#控制台应用程序,并且正在尝试检查我的主程序的进程何时退出,以便我可以在退出之前进行一些清理,但事件似乎永远不会触发.以下是设置事件处理程序的代码:
Process process = Process.GetCurrentProcess();
CloseConsoleHandler close = new CloseConsoleHandler(test);
process.EnableRaisingEvents = true;
process.Exited += close.CloseHandler;
//I also tried process.Exited += new EventHandler(close.CloseHandler);
Run Code Online (Sandbox Code Playgroud)
它似乎永远不会激发,不是当程序自然结束时,而不是当我单击关闭按钮时......从不.这甚至可能吗?
我试图在OSX Mavericks上安装sqlite3 gem,我遇到了一个看起来很棘手的错误.通过谷歌搜索,我没有设法找到有同样问题的其他人.
基本上,当我运行gem install命令时,会发生以下情况:
Building native extensions. This could take a while...
ERROR: Error installing sqlite3:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb
checking for sqlite3.h... yes
checking for sqlite3_libversion_number() in -lsqlite3... yes
checking for rb_proc_arity()... yes
checking for rb_integer_pack()... no
checking for sqlite3_initialize()... yes
checking for sqlite3_backup_init()... yes
checking for sqlite3_column_database_name()... no
checking for sqlite3_enable_load_extension()... no
checking for sqlite3_load_extension()... no
checking for sqlite3_open_v2()... yes
checking for sqlite3_prepare_v2()... yes
checking for sqlite3_int64 in sqlite3.h... yes
checking for …
Run Code Online (Sandbox Code Playgroud) 我有一个Web服务的客户端,我是通过WSDL使用Visual Studio服务引用开发的.它被配置为使用证书对请求进行签名,并且可以向服务发送请求,但服务会回复400 - 错误请求错误,因为除了我想要的签名之外还有一个额外的签名,具有多个<Reference>
标签,其使用HMAC-SHA1作为其签名方法.Web服务不支持HMAC-SHA1,因此请求被拒绝.但是,我甚至不想要或不需要这个其他签名,我不确定它的来源.以下是我的绑定配置:
<customBinding>
<binding name="mainBinding">
<security authenticationMode="MutualCertificate"
allowSerializedSigningTokenOnReply="true"
requireDerivedKeys="false"
requireSignatureConfirmation="false"/>
<httpsTransport />
</binding>
</customBinding>
Run Code Online (Sandbox Code Playgroud)
我也把它ProtectionLevel = System.Net.Security.ProtectionLevel.Sign
作为一部分ServiceContractAttribute
.
我的配置的哪一部分导致第二个签名?如何更改配置以便在我的请求中有一个签名?
编辑:
以下是发送的请求.为了突出不可取的部分,我把它分成几个部分,但实际上它是连续的.
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<a:Action s:mustUnderstand="1" u:Id="_1">[removed]</a:Action>
<a:MessageID u:Id="_2">[removed]</a:MessageID>
<a:ReplyTo u:Id="_3">
<a:Address>[removed]</a:Address>
</a:ReplyTo>
<a:To s:mustUnderstand="1" u:Id="_4">[removed]</a:To>
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<u:Timestamp u:Id="[removed]">
<u:Created>2017-05-11T08:59:25.681Z</u:Created>
<u:Expires>2017-05-11T09:04:25.681Z</u:Expires>
</u:Timestamp>
<e:EncryptedKey Id="[removed]" xmlns:e="http://www.w3.org/2001/04/xmlenc#">
[removed]
</e:EncryptedKey>
<o:BinarySecurityToken u:Id="[removed]" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3">[removed]</o:BinarySecurityToken>
Run Code Online (Sandbox Code Playgroud)
部分的开头我不想要
<Signature Id="_0" xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#hmac-sha1"/>
<Reference URI="#_1">
<Transforms>
<Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<DigestValue>[removed]</DigestValue>
</Reference> …
Run Code Online (Sandbox Code Playgroud)