本文整理汇总了Python中qa.forms.AskForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python AskForm.is_valid方法的具体用法?Python AskForm.is_valid怎么用?Python AskForm.is_valid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qa.forms.AskForm
的用法示例。
在下文中一共展示了AskForm.is_valid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_ask_page
# 需要导入模块: from qa.forms import AskForm [as 别名]
# 或者: from qa.forms.AskForm import is_valid [as 别名]
def add_ask_page(request):
logger.debug("add_ask_page() !")
if request.method == "POST":
logger.debug("add_ask_page(): method POST")
logger.debug("add_ask_page(): POST params - " + ", ".join(request.POST))
logger.debug("add_ask_page(): POST[author]=" + request.POST.get('author','-'))
form = AskForm(request.POST)
form._user = request.user
logger.debug("add_ask_page(): form created")
if form.is_valid():
logger.debug("add_ask_page(): form is valid")
question = form.save()
url = question.get_url()
return HttpResponseRedirect(url)
else:
logger.debug("add_ask_page(): form is not valid")
logger.debug("error:" + " ".join(form.errors))
else:
logger.debug("add_ask_page(): metod GET")
form = AskForm()
logger.debug("add_ask_page(): return render")
return render(request, 'add_ask.html', {
'form': form,
})
示例2: ask
# 需要导入模块: from qa.forms import AskForm [as 别名]
# 或者: from qa.forms.AskForm import is_valid [as 别名]
def ask(request):
"""Ask form."""
if request.method == 'POST':
form = AskForm(request.POST)
if form.is_valid():
params = {
'title': form.cleaned_data['title'],
'text': form.cleaned_data['text']
}
if request.user.is_authenticated():
params.update({'author': request.user})
question = Question(**params)
question.save()
return HttpResponseRedirect(
reverse('question', kwargs={'id': question.id})
)
else:
form = AskForm()
context = {'form': form}
return render(request, 'ask.html', context)
示例3: ask
# 需要导入模块: from qa.forms import AskForm [as 别名]
# 或者: from qa.forms.AskForm import is_valid [as 别名]
def ask(request):
if request.method == "POST":
form = AskForm(request.POST)
if form.is_valid():
quest = form.save()
return HttpResponseRedirect(quest.get_url())
else:
form = AskForm()
return render(request, 'ask.html', {'form': form})
示例4: ask
# 需要导入模块: from qa.forms import AskForm [as 别名]
# 或者: from qa.forms.AskForm import is_valid [as 别名]
def ask(request):
if request.method == 'POST':
form = AskForm(request.POST, user=request.user)
if form.is_valid():
question = form.save()
return redirect('question_detail', question_id=question.id)
else:
form = AskForm(user=request.user)
return render(request, 'qa/ask.html', {'form': form})
示例5: ask
# 需要导入模块: from qa.forms import AskForm [as 别名]
# 或者: from qa.forms.AskForm import is_valid [as 别名]
def ask(request):
if request.method == "POST":
form = AskForm(request.POST)
if form.is_valid():
url = form.save_and_get_url(request.user)
return HttpResponseRedirect(url)
else:
form = AskForm()
return render(request, "qa/ask.html", { "form" : form })
示例6: answer
# 需要导入模块: from qa.forms import AskForm [as 别名]
# 或者: from qa.forms.AskForm import is_valid [as 别名]
def answer(request):
form = AskForm(request.POST)
form._user = request.user
if form.is_valid():
question = form.save()
url = question.get_url()
return HttpResponseRedirect(url)
else:
return HttpResponseNotFound()
示例7: ask_add
# 需要导入模块: from qa.forms import AskForm [as 别名]
# 或者: from qa.forms.AskForm import is_valid [as 别名]
def ask_add(request):
if request.method == "POST":
form = AskForm(request.POST)
if form.is_valid():
question = form.save()
return HttpResponseRedirect("/question/"+str(question.id)+"/")
else:
form = AskForm()
return render(request, 'ask_add.html', {'form': form})
示例8: ask
# 需要导入模块: from qa.forms import AskForm [as 别名]
# 或者: from qa.forms.AskForm import is_valid [as 别名]
def ask(request, *args, **kwargs):
if request.method == "POST":
form = AskForm(request.POST)
form._user = request.user
if form.is_valid():
question = form.save()
return HttpResponseRedirect(question.get_url())
else:
form = AskForm()
return render(request, 'ask.html',{'form': form})
示例9: ask_add
# 需要导入模块: from qa.forms import AskForm [as 别名]
# 或者: from qa.forms.AskForm import is_valid [as 别名]
def ask_add(request):
if request.method == 'POST':
form = AskForm(request.POST)
if form.is_valid():
post = form.save()
# url = post.get_url()
return HttpResponseRedirect(reverse('question', args=[post.id]))
else:
form = AskForm()
return render(request, 'ask_add.html', { 'form': form })
示例10: ask
# 需要导入模块: from qa.forms import AskForm [as 别名]
# 或者: from qa.forms.AskForm import is_valid [as 别名]
def ask(request):
if request.method == 'POST':
form = AskForm(request.POST)
if form.is_valid():
question = form.save()
return HttpResponseRedirect(reverse('question', args=[question.id,]))
else:
form = AskForm()
return render(request, 'ask.html', {
'form' : form
})
示例11: ask
# 需要导入模块: from qa.forms import AskForm [as 别名]
# 或者: from qa.forms.AskForm import is_valid [as 别名]
def ask(request):
if request.method == 'POST':
form = AskForm(request.POST)
if form.is_valid():
post = form.save(commit=False)
post.author = request.user
post.save()
return HttpResponseRedirect('question' )
else:
form = AskForm()
return render(request, 'ask.html', {'form': form})
示例12: add_quest
# 需要导入模块: from qa.forms import AskForm [as 别名]
# 或者: from qa.forms.AskForm import is_valid [as 别名]
def add_quest(request):
if request.method == 'POST':
form = AskForm(request.POST)
if form.is_valid():
post = form.save()
return HttpResponseRedirect('/question/%s/' % post.id)
else:
form = AskForm()
return render(request, 'add_quest.html',{
'form': form,
})
示例13: ask
# 需要导入模块: from qa.forms import AskForm [as 别名]
# 或者: from qa.forms.AskForm import is_valid [as 别名]
def ask(request, *args, **kwargs):
if request.method == "POST":
form = AskForm(request.POST)
if request.user.is_authenticated():
form._user = request.user
if form.is_valid():
q = form.save()
return HttpResponseRedirect('/question/' + str(q.pk) + '/')
else:
form = AskForm()
return render(request, 'ask.html',{ 'form': form })
示例14: ask
# 需要导入模块: from qa.forms import AskForm [as 别名]
# 或者: from qa.forms.AskForm import is_valid [as 别名]
def ask(request):
if request.method == 'POST':
form = AskForm(request.POST)
if form.is_valid():
q = form.save(request.user)
url = q.get_url()
return HttpResponseRedirect(url)
else:
form = AskForm()
return render(request, 'question_add.html', {
'form': form
})
示例15: addAsk
# 需要导入模块: from qa.forms import AskForm [as 别名]
# 或者: from qa.forms.AskForm import is_valid [as 别名]
def addAsk(request):
if request.method == 'POST':
f = AskForm(request.POST)
if f.is_valid():
qid = f.save(request.POST.get('title'), request.POST.get('text'))
return HttpResponseRedirect('/question/'+str(qid)+'/')
else:
f = AskForm()
return render(request, 'ask.html',{
'form': f
})