1

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?

3
  • Can you post the HTML output so we can see what gets rendered? Commented Mar 18, 2013 at 1:21
  • Also since you're using Django 1.5, you should know that the get_profile method has been deprecated. Commented Mar 18, 2013 at 1:24
  • Hello all. I wasn't editing the proper HTML and PY files. I just migrated my work directory but Notepad++ still had records of those files. Problem solved. The telephone is now displayed. Thanks to all who helped out. Commented Mar 18, 2013 at 4:46

3 Answers 3

1

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>
Sign up to request clarification or add additional context in comments.

5 Comments

@Dombey Oh, OK, can you run python manage.py shell from your project root, and load the user's profile to show us what user.get_profile.telefono outputs?
@Dombey After you've loaded up your shell, you'll want to do from django.contrib.auth.models import User, and load the specified user object. From your original post, it looks like your username is root, so doing user = User.objects.get(username='root') will fetch your user. Then you can run user.get_profile.telefono.
Did that and got `AttributeError: 'function' object has no attribute 'telefono' .
@Nitzle Got u'88888-8888-8888 which is what I entered but it is still not displaying on the front page.
@Dombey See Ric's answer. Maybe you can also post the code from views.py in your original question so we can see how you render the template?
1

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.

1 Comment

You're right. I wasn't editing the proper HTML and PY files. I just migrated my work directory but Notepad++ still had records of those files. Problem solved. Thanks all.
1

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 %} 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.