I know there are explanations out there regarding this, but I didn't understand how to implement it in my code, so I am asking again.
I get the following error
ViewDoesNotExist at /answer_question/
'False' is not a callable or a dot-notation path
When I click the "Post your answer" button in my post.html form. It is like a Stack Overflow website.
I have an URL called answer_question/ in urls.py
path('answer_question/', views.answer_question, name="answer_question"),
Then I made a function in views.py
def answer_question(request):
return render(request, 'store/homepage.html')
def post(self, request):
form = HomeForm(request.POST)
if form.is_valid():
text = form.cleaned_data["post"]
print("TEXT = " + str(text))
This has to make a new answer in the database.
models.py
class Answer(models.Model):
title = models.CharField(max_length=200, null=True)
context = models.TextField(max_length=1702, blank=True, validators=[MaxLengthValidator(1702)])
date = models.DateField(("Date"), default=date.today)
author = models.ForeignKey(Customer, on_delete=models.CASCADE, null=True)
post = models.ForeignKey(Post, on_delete=models.CASCADE, null=True)
def __str__(self):
return self.title
As for the syntax I looked at: https://www.youtube.com/watch?v=wzZiONbtwiA and https://docs.djangoproject.com/en/3.1/topics/forms/
<form action="/answer_question/" method="post">
<div class="blogpost"><br><br>
<textarea name="answer-title-input" cols="20" rows="1" class="answer-title" maxlength="20" placeholder="Write a title here..." id="id_context"></textarea>
<br><br><hr><br>
<div class="blogpost-content">
<textarea name="answer-context-input" cols="80" rows="10" class="answer-input" maxlength="300" placeholder="Write an answer here..." id="id_context"></textarea>
<br>
<br>
<button type="submit" class="submit-answer-button">Post your answer</button>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…