def question_add(request): if request.method =='POST': form = AskForm(request.POST) form._user = request.user if form.is_valid(): question = form.save() url = question.get_url() return HttpResponseRedirect(url) else: form = AskForm() form._user = request.user return render(request, 'question-add.html', { 'form': form })
def ask(request): if request.method == "POST": form = AskForm(request.POST) form._user = request.user if form.is_valid(): question = form.save() url = question.get_url() return HttpResponseRedirect(url) else: form = AskForm() return render(request, 'qa/ask_form.html', {'form': form})
def add_question(request): 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, 'add_question.html', { 'form': form, })
def ask(request): if request.method == "POST": form = AskForm(request.POST) if form.is_valid(): form._user = request.user post = form.save() #redirect_url = post.get_url() redirect_url = reverse('question_detail', args=[post.id]) return HttpResponseRedirect(redirect_url) else: form = AskForm() return render(request, 'ask.html', {'form': form})
def ask(request): if request.method == "POST": form = AskForm(request.POST) if form.is_valid(): form._user = request.user question = form.save() url = question.get_url() return HttpResponseRedirect(url) else: form = AskForm() return render(request, 'qa/ask.html', { 'form': form, })
def ask_add(request): if request.method == 'POST': form = AskForm(request.POST) if form.is_valid(): form._user = request.user question = form.save() # url = question.get_url() # return HttpResponseRedirect(reverse(url)) return HttpResponseRedirect(reverse('question', args=[question.id])) else: form = AskForm() return render(request, 'ask_add_page.html', {'form': form})
def post_ask_add(request, *args): if request.method == "POST": form = AskForm(request.POST) form._user = request.user if form.is_valid(): post = form.save() #url = post.get_url() return HttpResponseRedirect('/question/'+str(post.id)+'/') else: form = AskForm() return render(request, 'tpl_post_ask_add.html', { 'form': form })
def ask(request): if request.method == "POST": try: form = AskForm(request.POST) if form.is_valid(): form._user = request.user post = form.save() redirect_url = post.get_absolute_url() print 'redirect to: ', redirect_url return HttpResponseRedirect(redirect_url) except Exception as error_message: print error_message else: form = AskForm() return render(request, 'ask.html', {'form': form})
def ask(request, *args, **kwargs): if (request.method == 'GET'): form = AskForm() else: form = AskForm(request.POST) form._user = request.user if (form.is_valid()): post = form.save() url = post.get_absolute_url() return HttpResponseRedirect(url) return render(request, 'ask.html',{ "form": form, "_user" : request.user })
def ask(request): if request.method == 'POST': if request.user.is_authenticated(): form = AskForm(request.POST) form._user = request.user if form.is_valid(): question = form.save() url = question.get_url() return HttpResponseRedirect(url) else: return HttpResponseRedirect(default_url) else: form = AskForm() return render(request, 'ask_form.html',{ 'form':form, })
def ask(request): if request.method == "POST": ask_form = AskForm(request.POST or None) ask_form._user = request.user if ask_form.is_valid(): post = ask_form.save() url = post.get_url() print("____DEBUG: {}".format(url)) return HttpResponseRedirect(url) else: ask_form = AskForm() context = { "ask_form": ask_form, } return render(request, 'ask.html', context)