我想在视图中设置一个cookie,然后让该视图呈现一个模板.据我了解,这是设置cookie的方法:
def index(request):
response = HttpResponse('blah')
response.set_cookie('id', 1)
return response
Run Code Online (Sandbox Code Playgroud)
但是,我想设置一个cookie,然后渲染一个模板,如下所示:
def index(request, template):
response_obj = HttpResponse('blah')
response_obj.set_cookie('id', 1)
return render_to_response(template, response_obj) # <= Doesn't work
Run Code Online (Sandbox Code Playgroud)
模板将包含链接,单击这些链接将执行其他视图,以检查我正在设置的cookie.我在上面第二个例子中展示的是什么?我知道我可以创建一个包含我的模板的所有HTML的字符串,并将该字符串作为参数传递给HttpResponse,但这看起来真的很难看.有没有更好的方法来做到这一点?谢谢.
比方说,你有两个不同的C#类A,并B说,虽然不是来自同一个基类派生你分享一些对方法的同名.例如,两个类都有一个connect和一个disconnect方法,以及其他几个类.我希望能够编写一次适用于这两种类型的代码.
这是我想要做的简化示例:
public void make_connection(Object x)
{
x.connect() ;
// Do some more stuff...
x.disconnect() ;
return ;
}
Run Code Online (Sandbox Code Playgroud)
当然,这不会编译,因为Object类没有connect或disconnect方法.
有没有办法做到这一点?
UPDATE.我应该从一开始就明确这一点:我只有A和B的DLL,而不是源代码.
在学习Python的数据模型时,我正在使用该__new__方法从现有对象创建对象.以下是一些创建各种类型的新对象的示例:
x = 2; print type(x).__new__(x.__class__)
x = {}; print type(x).__new__(x.__class__)
x = [1,2]; print type(x).__new__(x.__class__)
x = 2.34; print type(x).__new__(x.__class__)
x = '13'; print type(x).__new__(x.__class__)
x = 1.0j; print type(x).__new__(x.__class__)
x = True; print type(x).__new__(x.__class__)
x = (1,2); print type(x).__new__(x.__class__)
Run Code Online (Sandbox Code Playgroud)
但是,以下三个实验给出了错误:
x = None; print type(x).__new__(x.__class__)
x = lambda z: z**2; print type(x).__new__(x.__class__)
x = object; print type(x).__new__(x.__class__)
Run Code Online (Sandbox Code Playgroud)
错误是(分别):
TypeError: object.__new__(NoneType) is not safe, use NoneType.__new__()
TypeError: Required argument 'code' (pos 1) not found
TypeError: type() takes …Run Code Online (Sandbox Code Playgroud) 我需要知道symfony项目中的数据库名称和数据库服务器名称.如何在symfony中使用编程方式访问当前数据库连接设置(使用Doctrine)?
在MSDN站点上有一些C#代码的示例,它显示了如何使用POST数据发出Web请求.以下是该代码的摘录:
WebRequest request = WebRequest.Create ("http://www.contoso.com/PostAccepter.aspx ");
request.Method = "POST";
string postData = "This is a test that posts this string to a Web server.";
byte[] byteArray = Encoding.UTF8.GetBytes (postData); // (*)
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream ();
dataStream.Write (byteArray, 0, byteArray.Length);
dataStream.Close ();
WebResponse response = request.GetResponse ();
...more...
Run Code Online (Sandbox Code Playgroud)
标记(*)的线是令我困惑的线.不应该使用UrlEncode方法而不是UTF8对数据进行编码吗?这不是什么application/x-www-form-urlencoded暗示?
当你输入
rake routes
Run Code Online (Sandbox Code Playgroud)
一堆路线出来了,但他们在哪里定义???
我知道有些是默认的,其他的怎么样?
例如,这是一个来自控制器的脚本,我试图从do_something中取消's',但是不能使它工作....它们是否也定义在其他地方?此外,他们什么时候采取参数,什么时候不参加,我怎么知道它?谢谢!
def hello
redirect_to do_things_shop_path(shop)
end
def do_things
end
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用设置Python包setup.py.我的目录结构如下所示:
setup.py
baxter/
__init__.py
baxter.py
tests/
test_baxter.py
Run Code Online (Sandbox Code Playgroud)
这是setup.py:
from setuptools import setup, find_packages
setup(name='baxter',
version='1.0',
packages=find_packages()
)
Run Code Online (Sandbox Code Playgroud)
我先做一个python setup.py build.当我运行时,python setup.py test我立即得到这个结果:
running test
Run Code Online (Sandbox Code Playgroud)
没有别的.单元测试没有运行,因为测试需要至少15秒才能完成,并且消息立即running test返回.
所以似乎python setup.py test没有找到单元测试.我究竟做错了什么?
.gitlab-ci.yaml我们有一个用于构建软件包的GitLab CI/CD文件。它.gitlab-ci.yaml有一个变量,用于确定应为哪个操作系统版本构建软件包。我们希望include在其他 GitLab 项目中使用关键字来包含此内容.gitlab-ci.yaml,以便我们构建包。我们希望为多个操作系统版本构建此软件包。但是,我们不能,因为 GitLab 不允许我们使用include同一个文件两次。还有其他方法可以做到这一点吗?
为了更具体地看到这一点,假设.gitlab-ci.yaml我们要包含在其他项目中的文件是这样的:
# common/gitlab-templates/.gitlab-ci.yaml
variables:
OS_RELEASE: 10.0
build-package:
script: echo "building for $OS_RELEASE"
Run Code Online (Sandbox Code Playgroud)
在另一个 GitLab 项目中,我们想做这样的事情:
# Build for version 8.0
include:
- project: 'common/gitlab-templates'
file: '.gitlab-ci.yml'
variables:
OS_RELEASE: 8.0
# Build for version 9.0
include:
- project: 'common/gitlab-templates'
file: '.gitlab-ci.yml'
variables:
OS_RELEASE: 9.0
# Build for version 10.0
include:
- project: 'common/gitlab-templates'
file: '.gitlab-ci.yml'
variables:
OS_RELEASE: 10.0
Run Code Online (Sandbox Code Playgroud)
但是,上面的语法无效.gitlab-ci.yaml。
我们如何解决这个问题?
使用 OpenSSL 库,可以通过执行以下操作创建 CSR(证书签名请求):
openssl genrsa -out rsa.key 1024
openssl req -new -key rsa.key -out output.csr -config config.txt
Run Code Online (Sandbox Code Playgroud)
其中config.txt包含要在证书中使用的专有名称。
我想在 Windows 下使用 C# 做类似的事情。但是,该方法createPKCS10不需要您提供 RSA 密钥。
有没有办法让 C# 生成一个显式的 RSA 私钥,然后使用该私钥创建 CSR?
我在Windows上使用新泽西SML.如果test.sml是SML文件,我可以通过在Windows命令提示符下运行它来执行它:
C:\> sml test.sml
Run Code Online (Sandbox Code Playgroud)
然后我得到通常的SML输出和一个新的SML命令提示符.
Standard ML of New Jersey v110.75 [built: Sat Sep 29 12:51:13 2012]
[opening hw1.sml]
val d2 = (1,1) : int * int
val d3 = (1,1) : int * int
val d4 = (2,1) : int * int
val d5 = (1,2) : int * int
val x7 = true : bool
-
Run Code Online (Sandbox Code Playgroud)
我想要的是退出到Windows命令提示符而不是留在SML交互模式.
我怎样才能做到这一点?
c# ×3
python ×2
windows ×2
cookies ×1
django ×1
django-views ×1
doctrine ×1
gitlab-ci ×1
object ×1
routes ×1
setuptools ×1
sml ×1
symfony ×1
symfony1 ×1
test-suite ×1
types ×1
unit-testing ×1
urlencode ×1
utf-8 ×1