python - 显示值 Django Python

标签 python django

enter image description here我正在 Windows Vista 上使用 Python 2.7 在 Django 1.4.3 中进行编程。我正在尝试在 localhost:8000/admin 中输入用户的功能,例如电话,然后显示在前端网页上。我的首页有 index.html:

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

它正在提取 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

但是,当我输入telefono(电话)值后,首页不显示它。我已附上我收到的首页。该数字应出现在鱼片图像下方。问题出在哪里?

最佳答案

看起来您已经注释掉了该值。 <!---->被视为 HTML 中的注释。

从技术上讲,django 模板仍在呈现该值,因为它们使用不同的注释格式,但您的浏览器会看到注释标记,然后隐藏内容。

更改此行:

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

对此:

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

关于python - 显示值 Django Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15468281/

相关文章:

python - 我的代码跳过 IF block 并转到 ELSE

python - 从具有最小值总和的不同表中选择唯一记录

python - 使用 Selenium (Python) 在 svg 中获取路径

python - 如何在imblearn中使用比率= 'dict'的随机欠采样器?

python - Django Rest Framework - 嵌套序列化不嵌套

python - Django 文件上传和模型 FileField

python - 无法找出 Heroku 应用程序失败的位置 [错误 : pg_config executable not found.]

django - 如何在 django rest 框架中包含模型序列化的相关字段?

django - 在 Django 模型中表示 URL 的最佳方式是什么?

python - django-rest-framework-接受提交的外键字段的ID