本文整理汇总了Python中qa.forms.AskForm.user方法的典型用法代码示例。如果您正苦于以下问题:Python AskForm.user方法的具体用法?Python AskForm.user怎么用?Python AskForm.user使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qa.forms.AskForm
的用法示例。
在下文中一共展示了AskForm.user方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ask
# 需要导入模块: from qa.forms import AskForm [as 别名]
# 或者: from qa.forms.AskForm import user [as 别名]
def ask(request):
if request.method == 'POST':
question = AskForm(request.POST)
if question.is_valid():
question.user = request.user
question = question.save()
return HttpResponseRedirect(question.get_url())
else:
question = AskForm()
return render(request, 'ask.html', {
'question': question,
})
示例2: question_add
# 需要导入模块: from qa.forms import AskForm [as 别名]
# 或者: from qa.forms.AskForm import user [as 别名]
def question_add(request):
user = request.user
if user.is_anonymous():
return HttpResponseRedirect(reverse('login'))
if request.method == 'POST':
form = AskForm(request.POST)
form.user = user
if form.is_valid():
question = form.save()
return HttpResponseRedirect(reverse('question_details', kwargs={'question_id': question.id}))
else:
form = AskForm()
return render(request, 'qa/question_add.html', {
"form": form
})
示例3: question_add
# 需要导入模块: from qa.forms import AskForm [as 别名]
# 或者: from qa.forms.AskForm import user [as 别名]
def question_add(request):
user = request.user
#if not user.is_authenticated():
# return HttpResponseRedirect('/')
if request.method == "POST":# and user is not None and user.is_active:
form = AskForm(request.POST)
form.user=request.user
#text = request.POST['text']
#title = request.POST['title']
#form = AskForm(user, text=text, title=title)
if form.is_valid():
question = form.save()
#return HttpResponseRedirect("/question/%s/" %question.id)
return HttpResponseRedirect("/question/"+str(question.id)+"/")
#return redirect('question_details', question.id)
#return redirect("/question/%s/" %question.id)
else:
form = AskForm()
return render(request, 'qa/question_add.html', {
'form': form
})