1👍
✅
From the Django docs for HttpResponse:
…if you want to add content incrementally, you can use response as a file-like object:
>>> response = HttpResponse()
>>> response.write("<p>Here's the text of the Web page.</p>")
>>> response.write("<p>Here's another paragraph.</p>")
https://docs.djangoproject.com/en/1.7/ref/request-response/#passing-strings
0👍
You would need to pass a list through the context, and then loop over the list in the template. For example:
views.py
def indexview(request):
data = []
for item in items_list:
data.append(item)
return render(request, 'index.html', {'data': data}
index.html
{% for item in data %}
{{ item }}
{% endfor %}
- [Answer]-Django cutom image name on upload
- [Answer]-Modify db object field from .py file in django
- [Answer]-Is my Django profiling middleware wrong?
- [Answer]-Optimal way to filter object from list of django model objects
- [Answer]-Django ModelForm: Making an "Other" Textarea manditory when the user selects "Other" from RadioSelect
0👍
I think you want to use the template system. (See Hybrid’s answer).
However, you can pass an iterator, instead of a string to HttpResponse
, and if necessary you can stream the results using, StreamingHttpResponse
.
def someview(request):
def mygen(data): # generator
for key, value in data.items():
yield value
data = {'a': 'Hello', 'b': 'Bye'}
g = mygen(data)
return StreamingHttpResponse(g)
- [Answer]-Many to many field in django is working in admin site but not in front end site form
- [Answer]-Object type instead of specific value from def __unicode__ showed in admin
- [Answer]-Django's ManyToManyField automatically adding a symmetric relationship between objects
- [Answer]-A light weight framework to host HTML files produced
Source:stackexchange.com