问题列表 - 第47448页

如何在django中设置或获取cookie值

这是我的代码:

from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django import http
from django.http import HttpResponse 

def main(request, template_name='index.html'):
    HttpResponse.set_cookie('logged_in_status', 'zjm1126')
    context ={
              'a':a,
              'cookie':HttpResponse.get_cookie('logged_in_status'),
    }

    return render_to_response(template_name, context)
    #return http.HttpResponsePermanentRedirect(template_name)
Run Code Online (Sandbox Code Playgroud)

它引发了这个例外:

unbound method set_cookie() must be called with HttpResponse instance as first argument (got str instance instead)
Run Code Online (Sandbox Code Playgroud)

我能做什么?

django cookies

33
推荐指数
1
解决办法
6万
查看次数

使用redis和memcached,我还应该使用session api吗?

如果我同时使用redis和memcached,那么仍然使用内置会话API是否有意义?

我知道rails上的ruby可以使用内置的api轻松使用memcached,但我想同时使用memcached和redis.

如果我必须手动访问redis,我何时根据请求连接到它?

memcached ruby-on-rails redis

3
推荐指数
1
解决办法
1360
查看次数

codeigniter活动记录,生成,但不执行查询

我正在工作一个库,需要将sql查询作为字符串提供给它的工作.

我正在使用CodeIgniter和他们的数据库类的活动记录实现.

我知道我可以像这样回应SQL语句......但我只想生成这个查询,而不是执行它.

 echo $this->db->last_query();
Run Code Online (Sandbox Code Playgroud)

任何帮助实现这一点都会很棒!

php activerecord codeigniter

2
推荐指数
2
解决办法
6985
查看次数

如何让Doxygen链接到Objective-C类的方法?

我正在使用Doxygen记录我的Objective-C代码,到目前为止它工作正常.

但是,我一直在搜索几个小时,但我找不到任何方法链接到方法.例如:

@interface Example : NSObject {
}

/** This is an example method I want to link to. */
- (void)methodWithArgument:(NSString*)one andArgument:(NSString*)two;

/** I want a link to methodWithArgument:andArgument: but Doxygen
 *  doesn't seem to link the two.
 */
- (void)someOtherMethod;

@end
Run Code Online (Sandbox Code Playgroud)

我的期望是methodWithArgument:andArgument:成为相应方法的链接,但在生成的文档中,它只是纯文本.

我尝试了很多其他形式:

methodWithArgument:andArgument:
-methodWithArgument:andArgument:
::methodWithArgument:andArgument:
Example::methodWithArgument:andArgument:
Run Code Online (Sandbox Code Playgroud)

但它们似乎都不起作用.是否有可能在Doxygen中链接Objective-C方法,如果是,如何?另外,如何链接到另一个类的方法?我知道如何为C,C++和Java做到这一点,但是对于Objective-C,我得到了答案.是不是Doxygen根本不支持Objective-C中的链接方法?这似乎是一个很大的缺点......

doxygen objective-c

8
推荐指数
1
解决办法
4494
查看次数

2
推荐指数
1
解决办法
2万
查看次数

获取包含Java中重复字符的字符串或组合的所有可能排列

我一直在尝试生成每个可能的4个字符串的列表,该字符串可以由任何给定的字符集组成.我已经使用一个函数从一组字符生成每4个字符组合,但每个字符只使用一次.我需要使用给定的一组字符的所有可能组合,例如:

String[] elements = {"a", "b", "c", "1", "2", "3"};
int[] indices;
CombinationGenerator x = new CombinationGenerator (elements.length, 4);
StringBuffer combination;
while (x.hasMore ()) {
  combination = new StringBuffer ();
  indices = x.getNext ();
  for (int i = 0; i < indices.length; i++) {
      combination.append (elements[indices[i]]);
  }
  System.out.println (combination.toString ());
}
Run Code Online (Sandbox Code Playgroud)

使用此处的CombinationGenerator类,将返回每个唯一的4个字符组合,例如:

'abcd' , 'abc1', 'acb2', 'acb1'
Run Code Online (Sandbox Code Playgroud)

但是,我希望每个可能使用给定字符创建的字符串.例如:

'aaaa', 'aaab', 'abc1', 'aac1', '11c2'
Run Code Online (Sandbox Code Playgroud)

我已经尝试了我能够找到或提出的每种递归和置换方法但是我很难得到比上面所有组合更多的东西,然后生成每个组合的每个排列,但我无法工作如何使用重复的字符创建一组组合.

任何帮助,甚至只是关于如何做到这一点的理论都会有所帮助.

java combinations permutation

7
推荐指数
2
解决办法
2万
查看次数

将XML转换为JSON格式

我必须将docx文件格式(以openXML格式)转换为JSON格式.我需要一些指导方针来做到这一点.提前致谢.

java xml json docx

19
推荐指数
4
解决办法
7万
查看次数

Spring:@PersistenceContext和@Autowired线程安全?

基于这个例子:

@Service
public class Purchase {
  @PersistenceContext
  private EntityManager em;

  @Autowired
  private PurchaseDAO dao;

  private String normalField;

  .... // methods, operations, etc
}
Run Code Online (Sandbox Code Playgroud)

如果我错了,请帮助纠正我:

  1. 服务类PurchasePurchaseDAO是由spring管理的单例
  2. 服务类的字段normalField不是线程安全的,因为singleton是许多人共享的单个对象
  3. 让我们假设@ Repository-annotated-PurchaseDAO没有任何字段,这意味着它的线程安全,将由spring自动注入
  4. EntityManager的实例也是一个线程安全的属性,因为@PersistenceContext将确保当前事务的实体管理器将被使用.

谢谢 !

spring jpa jpa-2.0

6
推荐指数
1
解决办法
7990
查看次数

如何使用C#禁用文本框上的复制,粘贴和删除功能

任何人都可以建议如何使用C#处理WinForms文本框中的剪切,复制和粘贴事件?

c# textbox winforms

24
推荐指数
3
解决办法
4万
查看次数

.NET System.Diagnostics.Stopwatch问题(返回值太低)

在我的电脑上,秒表的返回值太低了.例如,我指定时为200毫秒Thread.Sleep(1000).该程序应该等待1秒钟.我也测试过ManualResetEvent.WaitOne(1000)并得到了相同的结果.框架2.0和3.0都给出了这种奇怪的行为.我正在运行带有.NET Framework 3.5 SP1的Windows XP SP3.

这是我的测试结果(下面的代码):

1000 ms for DateTime.Now.Ticks
0201 ms for Stopwatch.ElapsedTicks
0142 ms for Stopwatch.ElapsedMilliseconds
0139 ms for Stopwatch.ElapsedTicks after Reset
0264 ms for Stopwatch.ElapsedTicks setting ThreadAffinity
0151 ms for Stopwatch.ElapsedTicks setting ProcessorAffinity (and more)
0371 ms for Stopwatch.ElapsedTicks with Syncronized object
Done!
Run Code Online (Sandbox Code Playgroud)

// Program.cs文件

class Program
{
    static void Main(string[] args)
    {
        StopWatchTest.Go();
        Console.WriteLine("Done!");
        Console.ReadLine();
    }
}
Run Code Online (Sandbox Code Playgroud)

// StopWatchTest.cs类

internal static class StopWatchTest
{
    public const int SleepTime = 1000;

    public …
Run Code Online (Sandbox Code Playgroud)

.net c# stopwatch

12
推荐指数
3
解决办法
7258
查看次数