Concerned_Citizen
Concerned_Citizen

Reputation: 6835

Displaying Values Django Python

enter image description here I am programming in Django 1.4.3 with Python 2.7 on Windows Vista. I am trying to input features for the user such as telephone in localhost:8000/admin and then display then on the front web page. I have index.html for the front page:

<!-- Shows the label on tab. -->
{% block title %} Inicio - Bienvenidos {% endblock %}
{% block content %} 
<p> Esta es mi primera pagina en Django </p>
{% if user.is_authenticated %}
    <p> Bienvenido  {{user.username}} </p>
    {% if user.get_profile.photo %}
        <img src="/media/{{user.get_profile.photo}}" width="100px" height="100px"/>
    {% endif %}
    {% if user.get_profile.telefono %}
        <p> Numero Tel:</p> {{user.get_profile.telefono}}</p>
    {% endif %}
{% endif %}
{% endblock %} 

And it is pulling input values defined in models.py:

from django.db import models
from django.contrib.auth.models import User
# Create your models here.

class userProfile(models.Model):

    def url(self, filename):
        ruta = "MultimediaData/Users/%s/%s"%(self.user.username, filename)
        return ruta

    user = models.OneToOneField(User)
    photo = models.ImageField(upload_to = url)
    telefono = models.CharField(max_length = 30)

    def __unicode__(self):
        return self.user.username

However, after I input the telefono (telephone) value, the front page does not display it. I have attached the front page I am getting. The number should appear under the fish fillets image. What seems to be the problem?

Upvotes: 1

Views: 160

Answers (3)

catherine
catherine

Reputation: 22808

To get user extended information:

View = request.user.get_profile().field_name
Template = user.userProfile.field_name

So to display user extended information in template, it must be

{% block title %} Inicio - Bienvenidos {% endblock %}
{% block content %} 
<p> Esta es mi primera pagina en Django </p>
{% if user.is_authenticated %}
    <p> Bienvenido  {{user.username}} </p>
    {% if user.userProfile.photo %}
        <img src="/media/{{user.userProfile.photo}}" width="100px" height="100px"/>
    {% endif %}
    {% if user.userProfile.telefono %}
        <p> Numero Tel:</p> {{user.userProfile.telefono}}</p>
    {% endif %}
{% endif %}
{% endblock %} 

Upvotes: 1

Ric
Ric

Reputation: 8805

I would make sure you are editing the page you think you are editing. Change the first line of content to:

<p> Esta es mi segunda pagina en Django. {{user.get_profile.telefono}}</p>

And make sure the text changes to segunda.

Upvotes: 1

Nitzle
Nitzle

Reputation: 2477

It looks like you have the the value commented out. <!-- and --> are considered comments in HTML.

Technically the django template is still rendering the value, since they use a different comment format, but your browser is seeing a comment tag and then hiding the content.

Change this line:

<p> Numero Tel:</p> <!--{{user.get_profile.telefono}}</p>-->

To this:

<p> Numero Tel:</p> {{user.get_profile.telefono}}</p>

Upvotes: 1

Related Questions