2👍
The problem is in these two lines
profile = User.objects.get(pk=request.user.id)
and
{% for item in profile.all %}
The first one will just return to you a single User
object. This object won’t have an all
attribute, so the second {% for %}
won’t be executed! Instead of the {% for %}
try {{ profile }}
.
Update
First of all, I really don’t know what this line
user = models.ForeignKey(User, unique=True)
does. Please remove it from there ! Now, I suppose that the User
is a normal django.contrib.auth.models.User
. If yes, then you can do the following in your template:
The user {{ profile.username }} has the following name: {{ profile.first_name }} {{ profile.last_name }}
etc etc – check the docs to see all the fields of User
: https://docs.djangoproject.com/en/dev/ref/contrib/auth/
0👍
to fetch all the User
objects
use:
profile = User.objects.all()
args['profile']= profile
and in html
{% if profile %}
{% for usr in profile %}
{{ usr }}
{% endfor %}
{% endif %}
- [Answered ]-Django Run Python script and Pass output to javascript file
- [Answered ]-What is the correct way to construct a Django ModelForm in a create/edit view?
- [Answered ]-Django REST Framework how to limit user access to certain serializer field
- [Answered ]-Upgrading django 1.6 to 1.7. Is there any change in Generic relations for "related_name"?
0👍
It seems like you are mistaking the code
{% for item in profile.all %}
{% endfor %}
To provide access to the fields of your model in your template.
Instead, to access user fields (data, attributes, etc.), you need to use the following in your template:
<tr>
<td>{{ profile.<user attribute> }}</td>
<td>{{ profile.username }}</td>
</tr>
See: https://docs.djangoproject.com/en/dev/topics/templates/