我正在使用Django教程进行Tango,我已经成功完成了教程,但是我在官方的Django民意调查教程中注意到了以下内容:
def vote(request, question_id):
p = get_object_or_404(Question, pk=question_id)
try:
selected_choice = p.choice_set.get(pk=request.POST['choice'])
except (KeyError, Choice.DoesNotExist):
# Redisplay the question voting form.
return render(request, 'polls/detail.html', {
'question': p,
'error_message': "You didn't select a choice.",
})
else:
selected_choice.votes += 1
selected_choice.save()
# Always return an HttpResponseRedirect after successfully dealing
# with POST data. This prevents data from being posted twice if a
# user hits the Back button.
return HttpResponseRedirect(reverse('polls:results', args=(p.id,)))
Run Code Online (Sandbox Code Playgroud)
这里要注意的部分是"在成功处理POST数据后总是返回一个HttpResponseRedirect".但是,在Tango with Django教程中:
def add_page(request, category_name_url):
context = RequestContext(request) …Run Code Online (Sandbox Code Playgroud) 是否可以向 a 提供种子ThreadLocalRandom?
它 看起来是不是。
/**
* Throws {@code UnsupportedOperationException}. Setting seeds in
* this generator is not supported.
*
* @throws UnsupportedOperationException always
*/
public void setSeed(long seed) {
if (initialized)
throw new UnsupportedOperationException();
rnd = (seed ^ multiplier) & mask;
}
Run Code Online (Sandbox Code Playgroud)
那么我们可以ThreadLocalRandom使用种子还是它不是为此而设计的?