Summary
Using Django 1.8, I'm trying to make a Function Based View that renders an html page that allows me to update the contents of the object. I'm able to get this to work by using the form.as_p as shown in the documentation here, but I can't get these values inside an html <input> as the value.
Issue
The issue is that only the first word appears and the rest of the text is cut off (e.g. for a html input tag, the value of 'Hello World Will' gets turned into 'Hello')
model.py
class Questions(model.Model):
title = models.CharField(max_length=512, null=False, blank=False)
forms.py
class QuestionsForm(forms.ModelForm):
class Meta:
model = Questions
fields = ('title', )
views.py
def advice_update(request, pk)
question_results = Questions.object.get(id=pk)
advice_form = QuestionsForm(request.POST or None, instance=question_results)
...
return render(request, 'advice/advice_update.html', {'advice_form': advice_form, 'question_results': question_results,})
advice_update.html
<form method='POST' action=''>{% csrf_token %}
# METHOD 1 - This code works and renders the form with paragraphs enclosed
# but I want more control
{{ advice_form.as_p }}
# METHOD 2 - When I try to get the value by itself, it works too
{{ advice_form.instance.title }} # E.g. 'Hello World'
{{ question_results.title }} # E.g. 'Hello World'
# METHOD 3 - When I try to put the text inside a 'value' tag in an 'input',
# the text gets cut off and only the first word appears in the input
# When I look at the console, I see the rest of the text in there.
<input id="id_title" type="text" name="title" class="form-control" value={{ question_results.title }}>
I tried a few things like adding autoescape and safe tags, but when I use METHOD 3, the value inside the tag of advice.html cuts off when there's a space (e.g. 'Hello World' turns into 'Hello').