def ask(request): if request.method == 'POST': form = QuestionForm(request.POST) if form.is_valid(): question = Question() question.user = request.user question.title = form.cleaned_data.get('title') question.description = form.cleaned_data.get('description') caretaker = QuestionCareTaker() caretaker.question = question caretaker.save() question.caretaker = caretaker question.save() question.caretaker.save() tags = form.cleaned_data.get('tags') question.create_tags(tags) return redirect('/questions/') else: return render(request, 'questions/ask.html', {'form': form}) else: form = QuestionForm() return render(request, 'questions/ask.html', {'form': form})
def ask(request): # 提问按钮 if request.method == 'POST': # post是提交问题 form = QuestionForm(request.POST) if form.is_valid(): question = Question() question.user = request.user question.title = form.cleaned_data.get('title') question.description = form.cleaned_data.get('description') question.save() tags = form.cleaned_data.get('tags') question.create_tags(tags) # 重定向到提问页面 return redirect('/questions/') else: return render(request, 'questions/ask.html', {'form': form}) else: # get是显示提问页面 form = QuestionForm() return render(request, 'questions/ask.html', {'form': form})
def ask(request): if request.method == "POST": form = QuestionForm(request.POST) if form.is_valid(): question = Question() question.user = request.user question.title = form.cleaned_data.get("title") question.description = form.cleaned_data.get("description") question.save() tags = form.cleaned_data.get("tags") question.create_tags(tags) return redirect("/questions/") else: return render(request, "questions/ask.html", {"form": form}) else: form = QuestionForm() return render(request, "questions/ask.html", {"form": form})
def ask(request): if request.method == 'POST': form = QuestionForm(request.POST) if form.is_valid(): question = Question() question.user = request.user question.title = form.cleaned_data.get('Titel') question.description = form.cleaned_data.get('Beschreibung') question.save() tags = form.cleaned_data.get('Schlagworte') question.create_tags(tags) return redirect('/questions/') else: return render(request, 'questions/ask.html', {'form': form}) else: form = QuestionForm() return render(request, 'questions/ask.html', {'form': form})
def test_question_answered_question(self): self.assertEqual(self.question_two, Question.get_answered()[0])
def test_question_non_answered_question(self): self.assertEqual(self.question_one, Question.get_unanswered()[0])
def unanswered(request): questions = Question.get_unanswered() return _questions(request, questions, 'unanswered')
def answered(request): questions = Question.get_answered() return _questions(request, questions, 'answered')
def unanswered(request): questions = Question.get_unanswered() return render(request, 'questions/questions.html', { 'questions': questions, 'active': 'unanswered' })
def unanswered(request): questions = Question.get_unanswered() return render(request, 'questions/questions.html', {'questions': questions, 'active': 'unanswered'})
def all(request): tag = request.session.get('TRIBE_TAG') questions = Question.get_all(tag) return _questions(request, questions, 'all')
def unanswered(request): tag = request.session.get('TRIBE_TAG') questions = Question.get_unanswered(tag) return _questions(request, questions, 'unanswered')
def unanswered(request): questions = Question.get_unanswered() return render(request, "questions/questions.html", {"questions": questions, "active": "unanswered"})