當前位置: 首頁>>代碼示例>>Python>>正文


Python forms.AskForm類代碼示例

本文整理匯總了Python中qa.forms.AskForm的典型用法代碼示例。如果您正苦於以下問題:Python AskForm類的具體用法?Python AskForm怎麽用?Python AskForm使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了AskForm類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: add_ask_page

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,
    })
開發者ID:soulondemand,項目名稱:django-expirience,代碼行數:25,代碼來源:views.py

示例2: ask

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)
開發者ID:greenleafs,項目名稱:webtech,代碼行數:25,代碼來源:views.py

示例3: ask

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})
開發者ID:MelroiN,項目名稱:web2,代碼行數:9,代碼來源:views.py

示例4: ask

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})
開發者ID:botinag,項目名稱:stepic,代碼行數:9,代碼來源:views.py

示例5: ask

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 })
開發者ID:kirimaks,項目名稱:stepic_web,代碼行數:9,代碼來源:views.py

示例6: ask_add

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})
開發者ID:altakh,項目名稱:web,代碼行數:9,代碼來源:views.py

示例7: answer

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()
開發者ID:borismu,項目名稱:tutorialWebDev,代碼行數:9,代碼來源:views.py

示例8: ask

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})
開發者ID:sinelnikovd,項目名稱:stepicWeb,代碼行數:10,代碼來源:views.py

示例9: ask_add

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 })
開發者ID:moofspb,項目名稱:stepic_web_project,代碼行數:10,代碼來源:views.py

示例10: ask

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})
開發者ID:orman071,項目名稱:dj,代碼行數:11,代碼來源:views.py

示例11: ask

def ask(request):
	print("is : " + str(request.user.is_authenticated()))
	if request.method == 'POST':
		form = AskForm(request.POST)
		q = form.save()
		q.author = reques.user
		q.save()
		return HttpResponseRedirect('/question/' + str(q.id))
	else:
		form = AskForm()
	return render(request, "qa/ask.html" , {'form': form})
開發者ID:AntonLitovka,項目名稱:testWeb,代碼行數:11,代碼來源:views.py

示例12: add_quest

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,
        })
開發者ID:gitenth,項目名稱:enth,代碼行數:11,代碼來源:qa_views.py

示例13: ask

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
    })
開發者ID:K-DOT,項目名稱:stepic_web,代碼行數:11,代碼來源:views.py

示例14: ask

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 })     
開發者ID:AlexSmirnof,項目名稱:web,代碼行數:11,代碼來源:views.py

示例15: ask

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
    })
開發者ID:avzabr,項目名稱:stepic-web-tech,代碼行數:12,代碼來源:views.py


注:本文中的qa.forms.AskForm類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。